java: unchecked call to getConstructor(java.lang.Class<?>...)
2022-09-02 20:21:14
我正在使用反射来构造一个将File作为参数的类(ConfigBuilder):
Class myClassType = Class.forName(className);
Class[] types = new Class[] { File.class };
Constructor cons = myClassType.getConstructor(types);
Object[] constructorArgs = new Object[] { myFile };
cb = (ConfigBuilder) cons.newInstance(constructorArgs);
但我得到这个警告:
warning: [unchecked] unchecked call to getConstructor(java.lang.Class<?>...) as a member of the raw type java.lang.Class
Constructor cons = myClassType.getConstructor(types);
显然,似乎getConstructor需要一个泛型类型,所以我尝试了这样的东西:
Class<?>[] types = new Class<?>[] { File.class };
但我收到相同的警告消息
任何想法?
大卫