hello - I have a question - can I use a Map with g...
# getting-started
n
hello - I have a question - can I use a Map with generics simmilar to that in kotlin?
Copy code
val objects = FXCollections.observableHashMap<KClass<A: BasicModel>, ObservableList<A: BasicModel>>()

inline fun <reified T: BasicModel> get(): ObservableList<T> {
    return objects[T::class]
}
k
can you elaborate a bit on what you want / isn't working
Copy code
val objects: ObservableMap<KClass<out BasicModel>, ObservableList<out BasicModel>> = FXCollections.observableHashMap()

inline fun <reified T: BasicModel> get(): ObservableList<T>? {
    @Suppress("UNCHECKED_CAST")
    return objects[T::class] as ObservableList<T>?
}
this is probably what you want? keep in mind that
objects[T::class]
returns a nullable
also specifying the type explicitly looks cleaner
n
Thanks - still trying to get used to slack 🙂 Ill try that.
Worked like a charm!