wood burning stoves 2.0*
The moose likes Java in General and the fly likes Is JDK5.0 Generics good ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is JDK5.0 Generics good ?" Watch "Is JDK5.0 Generics good ?" New topic
Author

Is JDK5.0 Generics good ?

Stev Chaos
Greenhorn

Joined: May 25, 2005
Posts: 7
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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...


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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


Tony Morris
Java Q&A (FAQ, Trivia)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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

Joined: Sep 16, 2005
Posts: 1780
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?


There is no emoticon for what I am feeling!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

That's just the Stockholm Syndrome at work.
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
>> 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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is JDK5.0 Generics good ?
 
Similar Threads
Generics
Generics
Generics
generics
Generics