Why Generics?



In Java5, the powers that be added generics.

Can someone please explain to me what value they add to Java? I think they
are one of the biggest (of many big) mistakes in C++. And I always felt
that they only reason they were in C++ was because it made the huge mistake
of not having a common root for the entire class hierarchy: Java's Object
type.

Java didn't need any language features to implement container classes
because of this. An reference of type Object can hold ANY Object.

The biggest objection I've ever heard to that is it forces you to cast down
when you extract from the container. Big deal!

That's nothing compared to what I've always had to go thru to make generics
work in C++.

Am I missing something or did C++ weenies invade the language committee?



.



Relevant Pages

  • Re: Java Generics: limitations?
    ... cannot go around and do something similar to what I've said, then Java ... generics cannot be called generics, ... have pointed out, the HasXY interface is not necessary, and could be ... public int getX(); ...
    (comp.lang.java.programmer)
  • Re: Getter & Setter
    ... ich zumBbeispiel auch nicht sicher bin was Row Types ... C++ und Ada machen das ebenfalls nicht (wobei Ada nur benannte Generics ... Performanz in Java hauptsächlich in den Methodenaufrufen zu finden ...
    (de.comp.lang.java)
  • Re: Getter & Setter
    ... ich zum bEispiel auch nicht sicher bin was Row Types ... C++ und Ada machen das ebenfalls nicht (wobei Ada nur benannte Generics ... su meinst eine starke, statische Typisierung mit einigen ... Performanz in Java hauptsächlich in den Methodenaufrufen zu finden ...
    (de.comp.lang.java)
  • Re: unsafe or unchecked operations
    ... Generics are by far the most complicated thing I have encountered in ... The Java Glossaryhttp://mindprod.com ... same warning ... But how does casting happen when 'filters!= null'? ...
    (comp.lang.java.help)
  • Re: why doesnt ruby have generics?
    ... Why would you bind to a type in a language that doesn't really care ... cannot have generics in a language whose variables are typeless as ... Listin Java.) ... In Ruby you can do neither: you cannot cast because variables are ...
    (comp.lang.ruby)