本文整理汇总了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("}");
}