Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/106#discussion_r15806801
--- Diff: utils/common/src/main/java/brooklyn/util/guava/TypeTokens.java ---
@@ -68,5 +73,25 @@
public static <T> Class<T> getRawRawType(TypeToken<T> token) {
return (Class)token.getRawType();
}
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static <T> TypeToken<Set<T>> setOf(Class<T> type) {
+ return (TypeToken) TypeToken.of(Set.class);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static <K,V> TypeToken<Map<K,V>> mapOf(Class<K> key, Class<V>
value) {
--- End diff --
Not sure I follow. I thought one of the points of `TypeToken` is that it
has the generics information at runtime (i.e. it is not lost through type
erasure). However, just casting `TypeToken.of(Map.class)` means it will not
have the generics at runtime. We need to declare a sub-class of `TypeToken` in
order to preserve the generics - i.e. TypeToken.of()
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/reflect/TypeToken.html
It feels like these utilities have a place (e.g. in removing compile
warnings about casting and missing generics etc), but do we subsequently rely
on the `TypeToken` still having the generics at runtime?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---