Generics
This page documents the results from the Generics whiteboard where all Javapolis 2006 participants were encouraged to participate with their ideas.
Shortened generic instance creation
This idea was to shorten the creation of long generic types.
The problem is that this is too long:
Map<String,<Pair<String,Integer>> map = new HashMap<String,<Pair<String,Integer>>();
Proposed syntax 1:
Map<String,<Pair<String,Integer>> map = new HashMap<>();
Proposed syntax 2:
var map = new HashMap<String,<Pair<String,Integer>>();
Proposed syntax 3:
final map = new HashMap<String,<Pair<String,Integer>>();
Proposed syntax 4:
map := new HashMap<String,<Pair<String,Integer>>();
Proposed syntax 5 for no-args constructor:
HashMap<String,<Pair<String,Integer>> map();
Comments included (syntax indicated if relevant):
- "I am sold! When will you have it done!" - syntax 1
- "Still too verbose" - syntax 1
- "What if you need explicit declaration" - syntax 2
- "Ewwww..." - syntax 2
- "Why not make types optional when obvious"
- "Because its rarely as obvious as you think"
- "Can't your IDE do this"
- Yes, but difficult to read"
There was a question as to whether this could be extended for use in anonymous creation when passing to a method:
public void someMethod(Map<String,<Pair<String,Integer>>) {..}
someMethod(new HashMap<>());
Self return type
This idea was to extend generics (covariant returns) to allow this as a return type.
There were no comments on this idea.