In Java you can have:
final Map<String, Supplier<Interface>> associations = new HashMap<>();
associations.put("first", One::new);
associations.put("second", Two::new);
In Kotlin this translates to:
val associations: MutableMap<String, Supplier<Interface>> = HashMap()
associations["first"] = Supplier(::One)
associations["second"] = Supplier(::Two)
Without kotlin-reflect, is this the only way or am I missing something? That doesn't look so good or Kotlinish imho.
Since someone occurred in inference errors, this is the complete code:
fun example() {
val associations: MutableMap<String, Supplier<Interface>> = HashMap()
associations["first"] = Supplier(::One)
associations["second"] = Supplier(::Two)
}
interface Interface
class One : Interface
class Two : Interface