public static void printType(Type type, boolean isDefinition)
{
if (type instanceof Class)
{
Class<?> t = (Class<?>) type;
System.out.print(t.getName());
}
else if (type instanceof TypeVariable)
{
TypeVariable<?> t = (TypeVariable<?>) type;
System.out.print(t.getName());
if (isDefinition)
printTypes(t.getBounds(), " extends ", " & ", "", false);
}
else if (type instanceof WildcardType)
{
WildcardType t = (WildcardType) type;
System.out.print("?");
printTypes(t.getUpperBounds(), " extends ", " & ", "", false);
printTypes(t.getLowerBounds(), " super ", " & ", "", false);
}
else if (type instanceof ParameterizedType)
{
ParameterizedType t = (ParameterizedType) type;
Type owner = t.getOwnerType();
if (owner != null)
{
printType(owner, false);
System.out.print(".");
}
printType(t.getRawType(), false);
printTypes(t.getActualTypeArguments(), "<", ", ", ">", false);
}
else if (type instanceof GenericArrayType)
{
GenericArrayType t = (GenericArrayType) type;
System.out.print("");
printType(t.getGenericComponentType(), isDefinition);
System.out.print("[]");
}
}
这里
type instanceof WildcardType
type instanceof ParameterizedType
type instanceof TypeVariable
type instanceof GenericArrayType
分别代表什么 作者: 刘伟平 时间: 2012-10-18 19:55
type是后面的子类作者: 李贺晓 时间: 2012-10-18 20:01
instanceof是Java的一个二元操作符,主要是用来测试它左边的对象是否是它右边的类的实例,如果是的话返回true
type instanceof WildcardType -----------WildcardType对象是否是type类的
type instanceof ParameterizedType
type instanceof TypeVariable
type instanceof GenericArrayType