本文整理匯總了Java中java.lang.reflect.Type.getTypeName方法的典型用法代碼示例。如果您正苦於以下問題:Java Type.getTypeName方法的具體用法?Java Type.getTypeName怎麽用?Java Type.getTypeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Type
的用法示例。
在下文中一共展示了Type.getTypeName方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import java.lang.reflect.Type; //導入方法依賴的package包/類
private static JavaType create(final ImplementClass implementClass, final Type type) {
if (type instanceof Class<?>) {
return new ClassJavaType(implementClass, (Class<?>) type);
} else if (type instanceof TypeVariable<?>) {
TypeVariable<?> variable = (TypeVariable<?>) type;
return createByParamName(implementClass, variable);
} else if (type instanceof GenericArrayType) {
GenericArrayType arrayType = (GenericArrayType) type;
return new ArrayJavaType(implementClass, arrayType);
} else if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
return new ParameterizedJavaType(implementClass, parameterizedType);
} else if (type instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) type;
return new WildcardJavaType(implementClass, wildcardType);
}
throw new IllegalArgumentException(type.getTypeName());
}
示例2: getReturnTypeParameters
import java.lang.reflect.Type; //導入方法依賴的package包/類
/**
* @param method {@link Method} object
* @return the actual type parameters used in the source code. Return <strong>empty</strong> list if no parametrized type
*/
public static List<String> getReturnTypeParameters(Method method) {
List<String> typeParameters = new ArrayList<>();
Type type = method.getGenericReturnType();
String typeName = type.getTypeName(); // ex: java.util.List<com.timeyang.search.entity.Person>, java.lang.Long
Pattern p = Pattern.compile("<((\\S+\\.?),?\\s*)>");
Matcher m = p.matcher(typeName);
while (m.find()) {
typeParameters.add(m.group(2));
}
return typeParameters;
}
示例3: toString
import java.lang.reflect.Type; //導入方法依賴的package包/類
@Override
public String toString() {
Type type = getParameterizedType();
String typename = type.getTypeName();
if (isVarArgs()) {
typename = typename.replaceFirst("\\[\\]$", "...");
}
final StringBuilder sb = new StringBuilder(Modifier.toString(getModifiers()));
if (sb.length() != 0) {
sb.append(' ');
}
return sb.append(typename).append(' ').append(getName()).toString();
}
示例4: matchType
import java.lang.reflect.Type; //導入方法依賴的package包/類
protected Result matchType(Object obj, Property prop, String path) throws ValidationException {
String expectedType = prop.getType();
if ("array".equals(expectedType)) {
expectedType = JSONArray.class.getName();
}
else if ("ref".equals(expectedType) || "object".equals(expectedType)) {
expectedType = JSONObject.class.getName();
}
else {
PrimitiveType type = PrimitiveType.fromName(prop.getType());
if (type != null) {
expectedType = type.getKeyClass().getName();
if (BigDecimal.class.getName().equals(expectedType))
expectedType = Double.class.getName();
}
else {
Type refType = ReflectionUtils.typeFromString(prop.getType());
if (refType != null)
expectedType = refType.getTypeName();
}
}
String foundType = obj.getClass().getName();
boolean match = foundType.equals(expectedType);
if (!match) {
// forgive rounded numeric types
if (BigDecimal.class.getName().equals(expectedType)) {
if (foundType.equals(Double.class.getName()) || foundType.equals(Integer.class.getName()))
match = true;
}
else if (Double.class.getName().equals(expectedType)) {
if (foundType.equals(Integer.class.getName()))
match = true;
}
else if (Integer.class.getName().equals(expectedType)) {
if (foundType.equals(Long.class.getName()) && "int64".equals(prop.getFormat()))
match = true;
}
}
if (match)
return new Result();
else
return new Result(BAD_REQUEST, path + ": expected " + expectedType + " but found " + foundType);
}
示例5: of
import java.lang.reflect.Type; //導入方法依賴的package包/類
public static MessageType of(Type t) {
return new MessageType(t.getTypeName());
}
示例6: getTypeName
import java.lang.reflect.Type; //導入方法依賴的package包/類
public static String getTypeName(Method method) {
Type type = method.getGenericReturnType();
String typeName = type.getTypeName(); // ex: java.util.List<com.timeyang.search.entity.Person>, java.lang.Long
return typeName;
}
示例7: getInnermostType
import java.lang.reflect.Type; //導入方法依賴的package包/類
/**
* If return type is genetic type, then return last parameterized type, else return the formal return type name of the method represented by this {@code Method} object.
* @param method {@link Method} method
* @return If return type is genetic type, then return last parameterized type, else return the formal return type name of the method represented by this {@code Method} object.
*/
public static String getInnermostType(Method method) {
Type type = method.getGenericReturnType();
String typeName = type.getTypeName(); // ex: java.util.List<com.timeyang.search.entity.Person>, java.lang.Long
String[] types = typeName.split(",\\s*|<|<|>+");
return types[types.length - 1];
}