0

I just installed jdk1.7.0_07 and I'm suddenly inundated with lots of warnings about generic raw types. (I'm getting hundreds of them and they obfuscate other, possibly meaningful warnings.) To the best of my knowledge these errors should not be generated and I didn't get them with java-6-openjdk-i386.

I've created the following minor example. (Each class is in its own file.)

public interface Generic<T> {
    public T get( );
}

public class Test {

    public Test safeAsHell( Generic thing, int number ) {
        return new Test( );
    }

    public void safeAsHell( Generic thing ) { }

}

When I try to compile this (javac -Xlint), I get the following warnings:

Test.java:3: warning: [rawtypes] found raw type: Generic
    public Test safeAsHell( Generic thing, int number ) {
                        ^
  missing type arguments for generic class Generic<T>
  where T is a type-variable:
    T extends Object declared in interface Generic
Test.java:7: warning: [rawtypes] found raw type: Generic
    public void safeAsHell( Generic thing ) { }
                        ^
  missing type arguments for generic class Generic<T>
  where T is a type-variable:
    T extends Object declared in interface Generic
2 warnings

Adding Object as a generic type parameter (Generic<Object> thing) solves the problem. I'd have thought the types Generic and Generic<Object> are equivalent. Am I overlooking something?

user1201210
  • 3,801
  • 22
  • 25
Marc van Dongen
  • 534
  • 4
  • 15

1 Answers1

2

Generic<Object> is a parameterized type while Generic is a raw type. That's why the warnings.

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
  • I just checked my copy of _`Java` Generics_ by Naftalin and Wadler and I couldn't find any cases where they didn't add type parameters so you may be right. Still I don't understand why I didn't get these errors before (I always compile with `-Xlint`). It looks as if I've got lots of cleaning up to do. – Marc van Dongen Oct 02 '12 at 04:23
  • @MarcvanDongen: It might be the open-jdk with that javac flag. I am not sure though, have never used open-jdk. I don't think you removed some suppress warning unchecked annotations. – Bhesh Gurung Oct 02 '12 at 04:28
  • Without the `-Xlint` flag I don't get the warnings. Adding the flag just forces `javac` to be very pedantic about what it thinks is unsafe. – Marc van Dongen Oct 02 '12 at 04:42