question on Kotlin generics if anyone thinks they ...
# announcements
h
question on Kotlin generics if anyone thinks they might be able to help! https://stackoverflow.com/questions/63992988/instantiating-classes-from-non-reified-type-parameters
e
JVM-specific: runtime types of objects are erased, but generic types on classes aren't
h
interesting
sadly that link only shows me a hello world
e
strange, works for me, but let me copy paste the code here:
h
thanks
e
Untitled
outputs:
Copy code
class java.lang.Integer
class java.lang.String
interface Foo
class Bar
h
ah I hadn’t even thought to use reflection to get a reference to the class of the type parameter!
that makes a lot of sense
e
it's definitely not foolproof. if you declare a generic subclass, this will fail
but in some restricted cases, it's useful
h
indeed
this use case is specific enough that it should be fine
would you like the SO points for answering my question or are you happy or me to post your solution btw?
thanks again
e
I haven't used SO in ages but I logged in to post for you 🙂
👍 1