What is the external Eclipse annotation format for static inner classes?

I am trying to write an Eclipse external annotation file for the static Map.Entry inner class. How to do it?

I created a file with a name Map$Entry.eeain a subfolder java/utilin the folder where all my external annotation files are located. Here are the contents of this file.

class java/util/Map$Entry

comparingByKey
 <K::Ljava/lang/Comparable<-TK;>;V:Ljava/lang/Object;>()Ljava/util/Comparator<Ljava/util/Map$Entry<TK;TV;>;>;
 <K::Ljava/lang/Comparable<-TK;>;V:Ljava/lang/Object;>()L1java/util/Comparator<L1java/util/Map$Entry<T1K;TV;>;>;

comparingByKey
 <K:Ljava/lang/Object;V:Ljava/lang/Object;>(Ljava/util/Comparator<-TK;>;)Ljava/util/Comparator<Ljava/util/Map$Entry<TK;TV;>;>;
 <K:Ljava/lang/Object;V:Ljava/lang/Object;>(L1java/util/Comparator<-TK;>;)L1java/util/Comparator<L1java/util/Map$Entry<TK;TV;>;>;

comparingByValue
 <K:Ljava/lang/Object;V::Ljava/lang/Comparable<-TV;>;>()Ljava/util/Comparator<Ljava/util/Map$Entry<TK;TV;>;>;
 <K:Ljava/lang/Object;V::Ljava/lang/Comparable<-TV;>;>()L1java/util/Comparator<L1java/util/Map$Entry<TK;T1V;>;>;

comparingByValue
 <K:Ljava/lang/Object;V:Ljava/lang/Object;>(Ljava/util/Comparator<-TV;>;)Ljava/util/Comparator<Ljava/util/Map$Entry<TK;TV;>;>;
 <K:Ljava/lang/Object;V:Ljava/lang/Object;>(L1java/util/Comparator<-TV;>;)L1java/util/Comparator<L1java/util/Map$Entry<TK;TV;>;>;

equals
 (Ljava/lang/Object;)Z
 (L0java/lang/Object;)Z

getKey
 ()TK;
 ()TK;

getValue
 ()TV;
 ()TV;

setValue
 (TV;)TV;
 (TV;)TV;

Eclipse marks a warning entry.getValue()in the following code:

Map.Entry<@Nullable String, @NonNull Object> entry;
@NonNull Object value = entry.getValue();

Warning:

Unsafe interpretation of method return type as '@NonNull' based on the receiver type
'Map.<@NonNull Entry<@Nullable String, @NonNull Object>>'. Type Map.Entry<K, V> doesn't seem
to be designed with null type annotations in mind.
+4
source share
2 answers

the second line after getValueshould be instead for : ()T1V; ()TV; @NonNull

class java/util/Map$Entry
getValue
 ()TV;
 ()T1V;

For @Nullableit will be ()T0V;

( ", , null" ), @NonNull Object value = entry.getValue();, entry Map.Entry<String, @Nullable Object>, Map.Entry<String, @NonNull Object>. Eclipse, Map.Entry , java/util/Map$Entry.eea :

class java/util/Map$Entry

, Map, @NonNull Object o = map.get("foo");. @Nullable:

class java/util/Map
get
 (Ljava/lang/Object;)TV;
 (Ljava/lang/Object;)T0V;

. : Eclipse 4.6 -

+1

Eclipse Oxygen (4.7.0) build 20170620-1800 . Map$Entry.eea , . Map.Entry V @NonNull , getValue() @NonNull. Map.Entry V @Nullable , getValue() @Nullable.

. ( ).

Map.Entry<@NonNull String, @Nullable Object> entry;
...
entry.getValue().toString();
0

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


All Articles