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

arekolek

02/13/2019, 1:47 PM
Why does the access of result annotated with
android.annotations.Nullable
generate a mere warning instead of an error?
j

Jay

02/13/2019, 2:11 PM
I’m new to android and Kotlin, but why isn’t it an optional? Is it to do with how it’s exposed from Java or something like that?
g

gumil

02/13/2019, 2:12 PM
Because it is a platform call and the compiler reads it as a type
String!
which can be of type
String
or
String?
a

arekolek

02/13/2019, 2:21 PM
Yeah, so I’m asking, why is it a platform type
Compare it with this:
image.png
Test is defined as:
Copy code
import androidx.annotation.Nullable;

public class Test {

    @Nullable
    public String getAction() {
        throw new RuntimeException();
    }

}
Why does the compiler understand the
androidx.annotation.Nullable
annotation but not the
android.annotation.Nullable
(the warning is coming from the linter, why can’t the compiler do that?)
j

jw

02/13/2019, 2:38 PM
The android.jar doesn't use
android.annotation.Nullable
. It rewrites the bytecode to use
android.annotation.RecentlyNullable
which only triggers a warning. It will be an error in Q.
👍 17
a

arekolek

02/13/2019, 3:03 PM
Ah, ok thanks, now I see the announcement https://android-developers.googleblog.com/2018/08/android-pie-sdk-is-now-more-kotlin.html
Normally, nullability contract violations in Kotlin result in compilation errors. But to ensure the newly annotated APIs are compatible with your existing code, we are using an internal mechanism provided by the Kotlin compiler team to mark the APIs as recently annotated. […] The goal is to provide you with sufficient time to update your code.
7 Views