|
|
@@ -58,17 +58,17 @@ import net.ranides.assira.reflection.ReflectUtils;
|
|
|
* @author ranides
|
|
|
*/
|
|
|
public abstract class TypeToken<T> implements Comparable<TypeToken<T>>, GenericClass {
|
|
|
-
|
|
|
+
|
|
|
private final Type type;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Tworzy nową instancję klasy TypeToken. Możliwe i sensowne tylko w formie
|
|
|
* utworzenia nowej klasy anonimowej, parametryzowanej typem, który chcemy
|
|
|
- * przekazać / przechować / wydedukować:
|
|
|
+ * przekazać / przechować / wydedukować:
|
|
|
* <pre>
|
|
|
* {@code new TypeToken<Integer>(){ } }
|
|
|
* </pre>
|
|
|
- *
|
|
|
+ *
|
|
|
*/
|
|
|
protected TypeToken()
|
|
|
{
|
|
|
@@ -85,17 +85,17 @@ public abstract class TypeToken<T> implements Comparable<TypeToken<T>>, GenericC
|
|
|
*/
|
|
|
type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Zwraca wydedukowany typ parametru. Bez dodatkowego wsparcia narzędzi
|
|
|
* wyodrębniających i przetwarzających otrzymaną informację niezbyt użyteczny.
|
|
|
- * @return
|
|
|
+ * @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Type type() {
|
|
|
- return type;
|
|
|
+ public Type type() {
|
|
|
+ return type;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* The only reason we define this method (and require implementation
|
|
|
* of <code>Comparable</code>) is to prevent constructing a
|
|
|
@@ -156,11 +156,11 @@ public abstract class TypeToken<T> implements Comparable<TypeToken<T>>, GenericC
|
|
|
public String toString() {
|
|
|
return ReflectUtils.sig(this);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* To przejdzie tylko wtedy, gdy wywołamy na rzecz klasy, która jest subklasą genericsa
|
|
|
* @param clazz
|
|
|
- * @return
|
|
|
+ * @return
|
|
|
*/
|
|
|
public static Class<?>[] getTypeArguments(Class<?> clazz) {
|
|
|
Type[] types = ((ParameterizedType)clazz.getGenericSuperclass()).getActualTypeArguments();
|
|
|
@@ -168,5 +168,7 @@ public abstract class TypeToken<T> implements Comparable<TypeToken<T>>, GenericC
|
|
|
for(int i=0; i<types.length; i++) { result[i] = (Class<?>)types[i]; }
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public static abstract class TT<Type> extends TypeToken<Type> { }
|
|
|
+
|
|
|
}
|