I started use JDK5.0 in a commerical project from this week. After I did some study, I personally don't think the design/implementation of the generics is good. Looks like the Sun is more interested in implement the 'template' in a different way, so that no one can say 'java steal c++'. In fact I think the C++ template approach is quit easy to understand and to use ( compared with Java !), I realy want to go back to the old STL days.
Another issue is that to make JDK5.0 backword compitable , the generics has to make many compromise.
I 'd like to hear your opionin and / or insight.
SCJP1.4, SCBCD<br />Signature: to be defined, but will include method name and arguments.
Originally posted by Jesper de Jong: Can you give some specific examples of what you think is not good about Java generics?
Generics were mainly designed to allow type safe collections. There are some strange quirks, like you can't make an array of a concrete parameterized type, see my blog entry for an explanation.
Otherwise I think generics are adequate and not overly complex. Maybe you just have to get used to them...
Your blog uses terminology which is somewhat misleading. Just what is a "concrete parameterized type"? Only you seem to know, and your readers will only find out when they look at the code samples. You might mean "you cannot create an array of a parameterized type, unless you use the unbounded wildcard, or you omit parameters to the type (and therefore, receiving a compile-time warning)". You also only scratch the surface with respect to the issues that arise from this lack of reverse compatibility. You could even digress further and point out the many inherent defects within arrays themselves (I'm pretty sure I summarised it on this forum not too long ago).
Just my two cents worth, and five cents is the smallest denomination in Australia, so it rounds down to nothing anyway
You also only scratch the surface with respect to the issues that arise from this lack of reverse compatibility.
My blog entry was not meant to give a complete overview of what's wrong with generics, I just wanted to highlight this one peculiarity.
So, do you have something to say about Stev's question? Any more examples of what's wrong with generics?
Joined: Sep 16, 2005
I'm suprised that anyone could write "the C++ template approach is quit easy to understand and to use" -- has he taken a butcher's hook at the STL? That's an encylcopedia of nasty hacks that really stretch the "macro substitution" nature of C++ templates. What are the semantics of C++ templates anyway? Is it just defined in terms of textual substitution?
>> I personally don't think the design/implementation of the generics is good
That's unfortunate. Why didn't you speak up earlier? You could have saved the Java community a lot of effort by letting them know this earlier. The brightest minds in the industry toiled over this for years analyzing C++ and other alternatives finally coming up with an effective solution that was compatible with existing Java code. Now we find out from you it's not good. Thanks. [ February 03, 2006: Message edited by: Rick O'Shay ]
First time I have seen someone mention the words "Marco Substitution" since my Foxpro days.
I think Generics are cool, I like type safety, so if I can add that safety to my code, in even more ways than in Collections, than I am going for it.
I won't say that Generics is perfect, but I wouldn't say that anything in this world is perfect, except when you add imperfectness to the equation of what defines the perfectness of an object. Kind of like a tree, a Tree is perfect because of its uniqueness to other trees due to some imperfections.