??????java????
???????????? ???????[ 2015/3/24 14:08:46 ] ????????Java ??????? ????? ???? ????
????????????????????????????????????????????????????????????????????÷???????Щ???????????????????????????ReflectionUtil??????????????????????????java.lang.reflect?????????????????????????????????(java.reflect.Type)?????????
???????????????????java????????????????????á???????????java???????????????????????Oracel????γ???????????????????????.
????ReflectionUtil?а??????????????
???????Type???????class;
???????Type????????;
???????????????????????;
??????????????????????????;
???????????????е????field????;
???????????????е????method????????;
?????????????????????????;
????ReflectionUtil??????.
???????Type???????class
private static final String TYPE_NAME_PREFIX = "class ";
public static String getClassName(Type type) {
if (type==null) {
return "";
}
String className = type.toString();
if (className.startsWith(TYPE_NAME_PREFIX)) {
className = className.substring(TYPE_NAME_PREFIX.length());
}
return className;
}
public static Class<?> getClass(Type type)
throws ClassNotFoundException {
String className = getClassName(type);
if (className==null || className.isEmpty()) {
return null;
}
return Class.forName(className);
}
????????ReflectionUtil#getClass(Type)??????java.lang.reflect.Type???java.lang.Class???????????????????Type??toString????????????????class????“class some.package.Foo”?????????class???????????Class.forName(String)???class????
???????Type????????
????public static Object newInstance(Type type)
????throws ClassNotFoundException?? InstantiationException?? IllegalAccessException {
????Class<?> clazz = getClass(type);
????if (clazz==null) {
????return null;
????}
????return clazz.newInstance();
????}
????????ReflectionUtil#newInstance(Type type)??????Type???????????????????????Type????????????????????????????????????Void???????InstantiationException????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11