Code example for ParameterizedType

Methods: getActualTypeArguments, getRawType

0
		Type t = getClass().getGenericSuperclass();
		if (!(t instanceof ParameterizedType)) {
			throw new RuntimeException("Invalid TypeToken; must specify type parameters");
		} 
		ParameterizedType pt = (ParameterizedType) t;
		if (pt.getRawType() != TypeToken.class) {
			throw new RuntimeException("Invalid TypeToken; must directly extend TypeToken");
		} 
		return pt.getActualTypeArguments()[0];
	} 
 
	/** 
	 * Gets type token for the given {@code Class} instance. 
	 */ 
	public static <T> TypeToken<T> get(Class<T> type) {
		return new TypeToken<T>(type) {};
	} 
 
	/** 
	 * Gets type token for the given {@code Type} instance. 
	 */