https://kotlinlang.org logo
#android
Title
# android
t

trevjones

01/02/2020, 4:35 PM
can someone explain me why
a.c.Intent.getStringExtra
returns a
String!
even though it is annotated with
android.annotation.Nullable
where as
a.os.BaseBundle.getString
returns a
String?
as expected based on the
a.a.Nullable
annotation that has seemingly no effect on the intent apis? inference and IDE seem to spot the issue, but the compiler DGAF
-Xjsr305=strict
has no effect here either. edit: If inferred as non null why does the compiler treat it like a platform type? Is that intended behavior or a bug?
j

jw

01/02/2020, 7:40 PM
Your image indicates that it does not
t

trevjones

01/02/2020, 7:43 PM
the IDE inference is correct. the compiler can't be seeing it the same or it would be a compile error. Perhaps it is just the difference between the new/old front end behaviors of plugin/compiler?
that does seem right either. turning on new inference in the compiler is still letting it through as a warning rather than error. Perhaps because the android Nullable is @hide so not in the byte code handed to the compiler? doesn't explain why the bundle api's work as expected. how does the kotlin compiler know about the annotations? is there an external mapping that it is fed? would the ordering of annotation and visibility modifier impact whatever toolchain is operating on this?
reworded the question in the OP
j

jw

01/03/2020, 1:50 AM
it's probably marked as recently non-null
in API N+1 it will be properly non-null
5 Views