I am trying to write an Eclipse External Annotation file for the static inner class Map.Entry. How do I do this?
I created a file named Map$Entry.eea
in the java/util
sub-folder under the folder where all of my External Annotation files are located. Here are the contents of that 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 still flags a warning on entry.getValue()
in the following code:
Map.Entry<@Nullable String, @NonNull Object> entry;
@NonNull Object value = entry.getValue();
The warning is:
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.
Upgrading to Eclipse Oxygen (4.7.0) build 20170620-1800 resolved the problem.
Map$Entry.eea
can be left as is in the question and the compiler warnings happen at the appropriate times. If theMap.Entry
V
is@NonNull
in code, thengetValue()
's return type is@NonNull
. If theMap.Entry
V
is@Nullable
in code, thengetValue()
's return type is@Nullable
.The code in the question no longer causes a compiler warning. The following code does (which is expected and desired).