Diamond with anonymous classes: what if anonymous class were generic

Zhong Yu zhong.j.yu at gmail.com
Wed Jun 24 18:30:53 UTC 2015

Currently, people use "super type token" trick [1] to create a sort of
"type literal". This trick depends on the fact that an anonymous class is

Otherwise, the following two cases may share the same class, and defeats
the trick.

    new TypeReference<List<String>>() {}

    new TypeReference<Set<Integer>>() {}

[1] http://gafter.blogspot.com/2006/12/super-type-tokens.html

PS - it's great to have diamond with anonymous class, particularly because
"super type token" would be much simpler in many use cases.

Zhong Yu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150624/e721195b/attachment.html>

More information about the compiler-dev mailing list