Duplicate :
|
One issue with generic which show pretty much immediatly when you start using them, is that it would be immensely practical to have some kind of alias statement, like C/C++ typedef. Consider this code: public class Example1 { private List<Pair<String,String>> internal; public Example1() { internal = new LinkedList<Pair<String,String>>(); } public Collection<Pair<String,String>> getInternal() { return new HashSet<Pair<String,String>>(internal); } } This is both painful to read, and painful to write. Compare with this: public class Example2 { public alias StringPair Pair<String,String>; private List<StringPair> internal; public Example2() { internal = new LinkedList<StringPair>(); } public Collection<StringPair> getInternal() { return new HashSet<StringPair>(internal); } } As I see it, this would greatly reduce typing, and increase readability. The feature is not hard to implement, since it only concerns compile time transformation. The only issue would be that of a new key word, but this alternate syntax could get away from that too: public StringPair = Pair<String,String>;