Caused by: java.lang.NoSuchMethodException: java.util.HashMap$EntrySet.<init>()
at java.lang.Class.getConstructor0(Class.java:2902) ~[na:1.7.0_80]
at java.lang.Class.getDeclaredConstructor(Class.java:2066) ~[na:1.7.0_80]
My JDK version is 1.7.0_80. The error message will happen again when I execute the following JUnit test code:
@Test
public void testGetDeclaredConstructor() throws NoSuchMethodException {
Map<String, Object> m1 = new HashMap<>();
Set<Map.Entry<String, Object>> entrySet = m1.entrySet();
Class clz = entrySet.getClass();
Constructor con = clz.getDeclaredConstructor();
con.setAccessible(true);
System.out.println("--------Test OK!");
}
HashMap$EntrySetis not part of any public API so any methods that it does or does not have (outside of the interfaces that it exposes) are implementation details that you should not depend on.Map.Entryis an interface. Interfaces does not have any constructors.