withTryGet

fun <T : Any, R> withTryGet(clazz: KClass<T>, factory: () -> T, block: (T) -> R): R(source)

Try to get a cached instance of type T, or create one if not cached.

Return

The result of block

Parameters

factory

Called only if the value is not already cached

block

Called with the (potentially cached) instance