• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Are Generics worth the trouble?

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just upgraded my WDSC and it now uses java 5.0. This is cool, except now I'm getting all these warnings pertaining to generics. Originally I didn't realize that this update was going to upgrade the compiler (guess I should have read the docs first). Since I was working in the earlier version of java I hadn't read up on the new version.

So after looking around the boards for a bit and seeing the issues that people are having with this I come to the question...

Is it really worth worrying about? My code is going to run the same as it did before if I don't go through and make a bunch of these generics in my eleventy thousand classes. Is it worth fixing up? What are the pros/cons of just suppressing the warnings and forgetting about it for now and just try to do it on new code?

Thanks guys.
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bryce,
Congratulations on being on Java 5. There are some cool features and productivity savings available to you now . You'll get used to them as you go.

It's definitely not worth changing all the legacy code to use generics! This is the kind of thing that you want to use for new code (or if you are significantly updating a class.) I can think of a few exceptions to this of course. If you have a common library, it could be worth changing its API so new Java 5 callers can use it more safely.

And sometimes there are times where Java 5 can make an API more powerful. We have on API that currently is implemented as:
public void myMethod(String arg1) {}
public void myMethod(String arg1, String arg2) {}
...
public void myMethod(String arg1, String arg2, ... String arg8) {}
public void myMethod(String[] args) {}
All of the earlier methods delegate to the final one and we have a TODO to remove the interim methods when we migrate to Java 5. This is a case where the API was designed with Java 5 in mind even though we aren't there yet.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is likely a compiler switch to stop warning you about the generics mismatches, if you're worried about it,

i'd definitely stay with Java5 !
 
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bill Shirley:
there is likely a compiler switch to stop warning you about the generics mismatches, if you're worried about it,

i'd definitely stay with Java5 !

Yes, there is, adding @SuppressWarnings("Unchecked") as an annotation (or something similar). But it is probably easier to ignore the warnings.

 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my experience, it's worth fixing the warnings while working on the code. I wouldn't go and fix them for code that I'm not going to touch right now otherwise.
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic