Java Code Examples for java.lang.reflect.Type#hashCode()
The following examples show how to use
java.lang.reflect.Type#hashCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoreTypes.java From crate with Apache License 2.0 | 6 votes |
/** * Returns the hashCode of {@code type}. */ public static int hashCode(Type type) { if (type instanceof Class) { // Class specifies hashCode(). return type.hashCode(); } else if (type instanceof ParameterizedType) { ParameterizedType p = (ParameterizedType) type; return Arrays.hashCode(p.getActualTypeArguments()) ^ p.getRawType().hashCode() ^ hashCodeOrZero(p.getOwnerType()); } else if (type instanceof GenericArrayType) { return hashCode(((GenericArrayType) type).getGenericComponentType()); } else if (type instanceof WildcardType) { WildcardType w = (WildcardType) type; return Arrays.hashCode(w.getLowerBounds()) ^ Arrays.hashCode(w.getUpperBounds()); } else { // This isn't a type we support. Probably a type variable return hashCodeOrZero(type); } }
Example 2
Source File: AnnotationUtils.java From deltaspike with Apache License 2.0 | 5 votes |
private static int getTypeHashCode(Type type) { int typeHash = type.hashCode(); if (typeHash == 0 && type instanceof Class) { return ((Class)type).getName().hashCode(); } return typeHash; }
Example 3
Source File: ReflectionUtils.java From deltaspike with Apache License 2.0 | 5 votes |
/** * We need this method as some weird JVMs return 0 as hashCode for classes. * In that case we return the hashCode of the String. */ public static int calculateHashCodeOfType(Type type) { int typeHash = type.hashCode(); if (typeHash == 0 && type instanceof Class) { return ((Class)type).getName().hashCode(); // the type.toString() is always the same: "java.lang.Class@<hexid>" // was: return type.toString().hashCode(); } return typeHash; }