Daniel Barbalace
Unregistered
|
|
It's unfortunate that Sun was too afraid of adding new reseved words to the language. Generics could have been made
much more readable by introducing two keywords: "of" and "isa". Now any programmer that is using "of" as a keyword
deserves to get burt for being foolish enough to use a predaticate to stand for an object (noun). Perhaps some
people have used "isa" as an identifier that is also an acronym for something. But those people can choose to either
stay at 1.4 or use the "search-and-replace" utility built in every single IDE and text editor to replace "isa" with
"myIsa". This could even been done recursively on a directory with a simple Java application or a script.
If we had "of" and "isa" reserve words, things become much clearer. We can replace awkward looking code as follows:
Instead of Vector <Dog> dogs = new Vector<Dog>(); say Vector of Dog dogs = new Vector of Dog();
Instead of Vector <? extends Mammal> pets = dogs; say Vector of Mammal pets = dogs; and know that this is valid because a Vector of Dog is a Vector of Mammal (since Dog extends Mammal)
Instead of class Mammals <T extends Mammal> { private Vector<T> items = new Vector<T>(); void add(T item) ... } say T isa Mammal; // T has file scope. Maybe it would be better to change T to AnyMammal class Mammals {
private Vector of T items = new Vector of T(); void add(T item) ... }
Instead of class Mammals<E extends Mammal> extends Vector<E> { } say E isa Mammal; // E has file scope. Maybe it would be better to change T to AnyMammal class Mammals extends Vector of E { }
Currently, Java does not have a file scope. However, letting a template name have scope of the local file (or
stream, if you are reading a class from a socket, database, etc.) is perfectly ok because the template name should
never, ever be used outstide the file. Therefore, there is need for a namespace either.
|
cyborg
Unregistered
|
|
That would be the Pascal style of doing things but Java is very much into the C style. Guess what syntax the generics is based off? Yes, it's the C++ style angle brackets. Sun don't want to scare off those C++ developers from Java by using verbose words rather than symbols!
|
|