One of the limitations of generics is type erasure. For example, the following code with FEST-Reflect will not compile:
List<String> powers = field("powers").ofType(List<String>.class())
.in(jedi)
.get();
|
Instead, we need to perform the following unsafe casting:
List<String> powers = (List<String>) field("powers").ofType(List.class())
.in(jedi)
.get();
|
Based on Neal Gafter's Super Type Tokens, is it possible to overcome this limitation:
List<String> powers = field("powers").ofType(new TypeRef<List<String>>() {})
.in(jedi)
.get();
|
TypeRef can be used to overcome erasure when: