tags:

views:

441

answers:

5

Should a future release of Java deprecate the use of raw types to force the migration to generics? I could also see having raw types not allowed by default but allowing them via a compile flag for legacy code.

A: 

There is no way to just migrate to generics

Peter
+3  A: 

Raw types are pretty much deprecated already. It is a compiler warning to use a ray type.

The behavior is just like a depreciated method. People just need to learn not to use the raw types.

jjnguy
+1  A: 

And break all of my old (pre-Java 5) code? I've tested that code already, and I assure you it is type-safe. No thanks.

Bill the Lizard
That was the reason I suggested the compile flag to allow raw types.
Paul Croarkin
In that case you can turn off unchecked warnings by using annotations using @SuppressWarnings("unchecked").
Bill the Lizard
The compiler already warns. Eclipse warns. A developer has to be pretty blinkered to not see these...
Bill Michell
I was talking about turning those off... just by selecting specific ones, though.
Bill the Lizard
+2  A: 

In Eclipse, you can instruct the compiler on how to handle raw types. By default, they are a Warning. But they can easily be set to Error. To change the settings:

Window > Preferences > Java > Compiler > Errors/Warnings > Generic Types

If you're working on an entirely new code base, you probably want to set that to Error in your project specific settings. Then check in your project files into your SCM so everyone gets the same project rules.

Brandon DuRette
This is how I work too. The only drawback is if you import a lot of pre 1.5 source into your codebase.
Mr. Shiny and New
+4  A: 

It should be noted that you can't deprecate the raw types; the generic types ARE the raw types. The compiler erases the type information when it creates the class files.

You can use compiler warnings or errors to enforce local coding policy. However there will be cases where you need to use raw types, such as if you are interfacing with an old library.

Mr. Shiny and New