Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is JDK5.0 Generics good ?

 
Stev Chaos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your blog uses terminology which is somewhat misleading. Just what is a "concrete parameterized type"?

I don't think "concrete parameterized type" is a very difficult term to understand, and as you say yourself it gets clear immediately if you look at my examples. By the way, I didn't invent this, I got it from Angelika Langer's excellent FAQ about generics: Can I create an array whose component type is a concrete parameterized type?

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?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's just the Stockholm Syndrome at work.
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> 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 ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
First time I have seen someone mention the words "Marco Substitution" since my Foxpro days.


Let me hasten to add that I used "macro substitution" to describe C++ templates, which is entirely accurate. Java generics are completely different, and I like Java's approach a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic