0

In the following pretty simple code:

public static void test(Map<Externalizable, Externalizable> t){
    for(Map.Entry<Externalizable, Externalizable> e : t.entrySet()){
      //The next line causes unchecked cast warning
      Object o = new AbstractMap.SimpleImmutableEntry(e.getKey(), e.getValue());
    }
  }

DEMO

Why? The AbstractMap.SimpleImmutableMap is a generic class. What's wrong?

user3663882
  • 6,957
  • 10
  • 51
  • 92

1 Answers1

2

Because you're using the raw type. Instead, use the diamond operator

Object o = new AbstractMap.SimpleImmutableEntry<>(e.getKey(), e.getValue());
Spotted
  • 4,021
  • 17
  • 33