Java 8 has type annotations so it can be used to infer type parameters inside collections. ```java @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. ```java static Map<String, /*@NotNull*/ String> map; ``` It brings an extra dependency though.
Java 8 has type annotations so it can be used to infer type parameters inside collections.
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.
It brings an extra dependency though.