@NonNull and @Nullable annotations - does performance affect Android?

Do @NonNull and @Nullable annotations affect Android performance while running? I mean, they only have the goal of supporting LINT and other tools for detecting possible errors, so they will probably / hopefully be ignored at compile time. Do you have sources confirming this?

+4
source share
2 answers

As a little experiment, I created the following method in an Android application:

private void test(@NonNull Object o) {
    o.toString();
}

, " " ApkTool smali :

.method private test(Ljava/lang/Object;)V
    .locals 0
    .param p1, "o"    # Ljava/lang/Object;
        .annotation build Landroid/support/annotation/NonNull;
        .end annotation
    .end param

    .prologue
    .line 22
    invoke-virtual {p1}, Ljava/lang/Object;->toString()Ljava/lang/String;

    .line 23
    return-void
.end method

, Nonnull .

Android, null . NullPointerExeption o.toString(), , . , .

, VM , null.

+2

@NonNull Nullable CLASS . -, VM .

, , , . , .

( , , , . )

+4

Source: https://habr.com/ru/post/1613080/


All Articles