Closed GoogleCodeExporter closed 9 years ago
Ben, I thought that we must have discussed this before, but I couldn't find a
record of it. What do you think? On the one hand, I get only a dozen hits in
Google code when searching for '<.*[)].*newProxy(Instance)?[(]'. On the other
hand, TypeToken support sounds logical, we don't require a lot of usages to
justify most reflection utilities, and I like to make unchecked warnings go
away. Of course, that's all assuming that this *is* safe.... I can never
convince myself for sure with TypeToken :) And I guess you could argue that,
since proxies necessarily use reflection, you're doing something "unchecked,"
anyway....
Original comment by cpov...@google.com
on 5 Nov 2013 at 10:20
It doesn't seem safe to me. For example:
static <T> List<T> sneakyCast(final List<?> list) {
return newProxy(new TypeToken<List<T>>() {}, new InvocationHandler() {
return method.invoke(list, args);
});
}
List<String> stringList = new ArrayList<>();
List<Integer> intList = sneakyCast(stringList);
intList.add(1);
If user has to provide a Class (IntList.class for example), the line of
method.invoke(list, args) will fail with CCE.
Original comment by be...@google.com
on 5 Nov 2013 at 11:32
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<issue id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:12
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:17
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
compulin...@gmail.com
on 5 Nov 2013 at 9:39