• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is JDK5.0 Generics good ?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's just the Stockholm Syndrome at work.
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic