that’s disappointing
# announcements
p
that’s disappointing
r
Yeah, but unfortunately there's no way around it, it's a JVM thing (type erasure if you google it).
p
yup
just took a moment for it to click for me
sorry for the noise!
e
for what it's worth, it is actually possible with
Array<T>
(on JVM)
Copy code
assertIs<Array<Int>>(arrayOf(1, 2, 3)) // pass
assertIs<Array<String>>(arrayOf(1, 2, 3)) // fail
due to the historical fact that array "class" has had a special representation since the beginning of Java
p
neat.
I think I’ll still update my assertion to take a mandatory class argument
e
not generic enough to implement generics on, so we ended up with type erasure for everything else for compatibility
p
so it’s clear to the caller that it’s only the actual class is guaranteed to be matched, not its type parameters
yeah…. type erasure was new when I was in college
I remember people grousing about it
e
yep, that would be reasonable
p
😆
e
I'm not sure if Kotlin/JS even bothers to keep a distinction between List and Array though
p
also, contracts are nifty!
heh.
I’m not sure if Kotlin/JS even bothers to keep a distinction between List and Array though
I wouldn’t be surprised either way
it does some things that are a little surprising if you’re interacting with kotlin/js-generated code from pure js, in order to maintain the state that kotlin expects!
n
Yeah, I remember finding this very rough in certain contexts when I first discovered it
I remember wanted to do a union on some classes I didn't control, so you need to use a sealed class, but you can't use the classes you don't control directly in the union because you can't make them inherit. So I just had a toy class to hold one member; i wanted to make it generic, but all this just doesn't work out because of type erasure. So you have to write a "holder" class separate for every type you want in the union