• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Are Generics worth the trouble?

 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • 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 !
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • 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.

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic