Package com.zfabrik.resources
Class TypeRef<T>
- java.lang.Object
-
- com.zfabrik.resources.TypeRef<T>
-
public abstract class TypeRef<T> extends java.lang.Object
A simple type reference to the be used to convey generic type information to type safe APIs such asIResourceLookup.lookup(String, com.zfabrik.resources.TypeRef)
. Based on the approach outlined in Neil Gafter's blog.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
cast(java.lang.Object o)
A cast method to T.boolean
equals(java.lang.Object obj)
java.lang.Class<T>
getClz()
Returns the represented class type, if this is what is represented.java.lang.Class<T>
getClz(boolean required)
Returns the represented class type, if this is what is represented.java.lang.reflect.Type
getType()
Return the type of the type parameter.int
hashCode()
java.lang.String
toString()
-
-
-
Constructor Detail
-
TypeRef
public TypeRef()
-
TypeRef
protected TypeRef(java.lang.Class<T> clz)
-
-
Method Detail
-
getType
public java.lang.reflect.Type getType()
Return the type of the type parameter.
-
getClz
public java.lang.Class<T> getClz()
Returns the represented class type, if this is what is represented. Otherwise returnnull
-
cast
public T cast(java.lang.Object o)
A cast method to T. Simply to avoid having using code handle warning for casts to parameterized types
-
getClz
public java.lang.Class<T> getClz(boolean required)
Returns the represented class type, if this is what is represented. Otherwise returnnull
, if required is passed asfalse
. Throws anIllegalStateException
, if no class type is represented and required is set totrue
. Returnsnull
, if no class type is represented and required is set tofalse
.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-