Skip to content
This repository was archived by the owner on May 12, 2020. It is now read-only.
This repository was archived by the owner on May 12, 2020. It is now read-only.

Support type annotations - JSR 308. #52

@bangarharshit

Description

@bangarharshit

Java 8 has type annotations so it can be used to infer type parameters inside collections.

@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface NotNull {
}

public class Java8Annotations {
  static Map<String, @NotNull String> map;
  public static void main(String[] args) {
  }
}

Unfortunately, it is not backported in android (min sdk=26, not sure if the app will crash for compile-time annotation).

One workaround is to use checker framework compiler - https://checkerframework.org/jsr308/ and use something like.

static Map<String, /*@NotNull*/ String> map;

It brings an extra dependency though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions