java.lang.Class
and
java.lang.reflect
java.lang.Class
were generified: getInterfaces()
,
getClasses()
.
getConstructors()
.
getMethod(String, Class...)
,
getConstructor(Class...)
, getDeclaredClasses()
,
getDeclaredConstructors()
,
getDeclaredMethod(String, Class...)
, and
getDeclaredConstructor(Class...)
. As a result,
code which uses these methods now produces warnings during
compilation.getDeclaredMethod()
:import java.lang.reflect.Method; public class Warning { void m() { try { Warning warn = new Warning(); Class c = warn.getClass(); Method m = c.getDeclaredMethod("m"); } catch (NoSuchMethodException x) { x.printStackTrace(); } } } $ javac Warning.java Note: Warning.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. $ javac -Xlint:unchecked Warning.java Warning.java:8: warning: [unchecked] unchecked call to getDeclaredMethod(java.lang.String,java.lang.Class<?>...) as a member of the raw type java.lang.Class Method m = c.getDeclaredMethod("m"); ^ 1 warning
To remove the warning, the declaration of c
should
be modified to include an appropriate generic type. In this case,
the declation should be:
Class<?> c = warn.getClass();
Method.toString()
and Constructor.toString()
now correctly display the set of modifiers.Array.newInstance(Class, int...)
is of variable
arity.The changes in java.lang.Class and java.lang.reflect
include: