Hi, i am a beginner in kotlin . I have a question ...
# announcements
a
Hi, i am a beginner in kotlin . I have a question , how can i find the data type of an array when initialized using
arrayof()?
for eg in this below example, i expected
Integer?
and
Object?
for cases #2 and #4
k
That is the java type. Java doesn't have a concept of nullability.
👍 3
s
Try just
x.javaClass
(without .name) - you’ll see what you expected
d
that has the same result, you're looking for
::x.returnType
s
has a different result for me 🤷
Maybe it’s just the way things get printed in Scratch
d
it's still the same java
Class
therefore you are not getting the result you're looking for with nullability
kotlin.String!
means unchecked nullability
s
I’m talking about line 6 from my screenshot, where you can see the type is
kotlin.Array<kotlin.Int?>
d
I dunno why it says that. It doesn't matter, the point is don't use a Java API if you want to discover nullability.
k
Left is the inferred Kotlin type while right of the equals sign is the string representation
👍🏻 1