|
|
リフレクション |
java.lang.Class の次のメソッドが汎用化されました: getInterfaces()、getClasses()、getConstructors()、getMethod(String, Class...)、getConstructor(Class...)、getDeclaredClasses()、getDeclaredConstructors()、getDeclaredMethod(String, Class...)、および getDeclaredConstructor(Class...)。
その結果、これらのメソッドを使用するコードは、コンパイル中に警告を生成します。
たとえば、次のコードは 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
警告を削除するには、適切な汎用型を含むように c の宣言を変更するようにしてください。この場合、宣言は次のようにするとよいでしょう。
Class<?> c = warn.getClass();
Method.toString() および Constructor.toString() が、修飾子のセットを正しく表示するようになりました。
Array.newInstance(Class, int...) の最後のパラメータが、可変引数に対応します。
|
Copyright © 2006 Sun Microsystems, Inc. All Rights Reserved.
|
|