3

In Java 6, using generics is optional. Code without generics does compile, but Eclipse takes issue with this, so I started wondering wether in higher Java versions the use of generics may become required, e.g.

Collection<?> foo = ...

will compile while

Collection foo = ...

won’t any more. Or: Can the compiler be forced to behave like this?—Something like Perl’s “use strict”?

In other words: Should one expect that work needs to be spent on generifying Java sources currently working fine, but not being equipped with generics? Is there some code backward compatibility guarantee by Oracle or not?

Searching for force generics or java require generics didn’t lead me to helpful information on that.

Community
  • 1
  • 1
Matthias Ronge
  • 9,403
  • 7
  • 47
  • 63
  • 2
    The designers took extra care for backward compatibly via type erasure. It must be for some valid reason :) – Jayan Apr 08 '13 at 08:00
  • Found a related one (if not duplicate): http://stackoverflow.com/questions/697879/javac-flag-to-disallow-raw-types – Jayan Apr 08 '13 at 08:10

3 Answers3

3

If raw types were not allowed, you wouldn't be allowed to use old code. However, you can configure Eclipse to generate an error. See in Window -> Preferences -> Java -> Compiler -> Errors/Warnings, in the section Generics Types.

WilQu
  • 7,131
  • 6
  • 30
  • 38
1

There's no definitive way to say for sure, but I highly doubt Oracle would both deprecate and invalidate a syntax structure. That would be like forcing you to use a diamond inference when it's not truly needed.

I can say with decent certainty that Oracle has no plans to remove syntax from Java. Too many people would complain (as in, almost everything would break).

1

IntelliJ too warns about use of raw type. It must be other IDEs as well. So , I guess, your case for actual build using CI/command line..

You can get compiler warnings (Xlint:unchecked) and some post processing.

Jayan
  • 18,003
  • 15
  • 89
  • 143