本文整理匯總了Java中java.lang.reflect.ParameterizedType.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java ParameterizedType.toString方法的具體用法?Java ParameterizedType.toString怎麽用?Java ParameterizedType.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.ParameterizedType
的用法示例。
在下文中一共展示了ParameterizedType.toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFieldTypeWithGeneric
import java.lang.reflect.ParameterizedType; //導入方法依賴的package包/類
@SuppressWarnings("all")
public static String getFieldTypeWithGeneric(Field f) {
Class fieldType = f.getType();
//TODO Anonymous Inner Class Cant be find By Class.fromName,but getName could.
String type = fieldType.getCanonicalName();
if (fieldType.isAssignableFrom(List.class)) {
try {
ParameterizedType pt = (ParameterizedType) f.getGenericType();
return pt.toString();
} catch (ClassCastException ignored) {
}
}
return type;
}
示例2: scanParameter
import java.lang.reflect.ParameterizedType; //導入方法依賴的package包/類
public static void scanParameter(Class<?> parameter, Set<Class<?>> checkSet, StringBuilder builder){
if(checkSet.contains(parameter) || parameter.isPrimitive() || parameter.isEnum()
|| parameter.getCanonicalName().startsWith("java.")){
return;
}
//Bean
checkSet.add(parameter);
Field fieldList[] = CodecUtils.getFields(parameter);
if(builder.lastIndexOf(",") != builder.length()-1){
builder.append(",");
}
builder.append("\"").append(parameter.getSimpleName()).append("\":{");
boolean isAdd = false;
for(Field field : fieldList){
Class<?> fieldClass = field.getType();
Type fType = field.getGenericType();
if(isAdd && builder.lastIndexOf(",") != builder.length()-1){
builder.append(",");
}
if(!isAdd){
isAdd = true;
}
if(fType instanceof ParameterizedType){
ParameterizedType pfType = (ParameterizedType)fType;
String typeStr = pfType.toString();
builder.append("\""+field.getName() +"\":").append("\""+typeStr +"\",");
getGenericField(typeStr, builder, checkSet);
} else {
if(fieldClass.isPrimitive() || fieldClass.isEnum() || fieldClass.getCanonicalName().startsWith("java.")){
builder.append("\""+field.getName() +"\":").append("\""+fieldClass.getCanonicalName() +"\",");
continue;
}
//自包類忽略
if(fieldClass.equals(parameter)){
builder.append("\""+field.getName() +"\":").append("\""+fieldClass.getCanonicalName() +"\",");
continue;
}
if(fieldClass.isArray()){
builder.append("\""+field.getName() +"\":").append("\""+fieldClass.getCanonicalName() +"\",");
Class comClass = fieldClass.getComponentType();
while(comClass.isArray()){
comClass = comClass.getComponentType();
}
scanParameter(comClass, checkSet, builder);
continue;
}
scanParameter(fieldClass, checkSet, builder);
}
}
if(builder.lastIndexOf(",") == builder.length() - 1){
builder.deleteCharAt(builder.length()-1);
}
builder.append("}");
}