-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
5.0
-
generic, x86
-
generic, windows_xp
I have faced a weird issue while using generics (on JDK 1.5.0 update 3 for Windows).
Consider the following simple example.
public class Foo {
public class FooInner<T> { }
public <T> FooInner<T> getInner() { return null; }
}
public class Bar {
final Foo foo=new Foo();
public Foo.FooInner<Void> i1=foo.getInner(); // incompatible types error on separate compilation
public Foo.FooInner<Long> i2=foo.<Long>getInner(); // incompatible types error on separate compilation
}
If I compile the both files together
$ javac Foo.java Bar.java
they are compiled fine without any errors or warnings (exactly as I expect).
However, if I then compile just Bar.java
$ javac Bar.java
I get the following errors:
Bar.java:4: incompatible types; no instance(s) of type variable(s) T exist so that Foo.FooInner<T> conforms to Foo.FooInner<java.lang.Void>
found : <T>Foo.FooInner<T>
required: Foo.FooInner<java.lang.Void>
public Foo.FooInner<Void> i1=foo.getInner();
^
Bar.java:5: incompatible types
found : Foo.FooInner<java.lang.Long>
required: Foo.FooInner<java.lang.Long>
public Foo.FooInner<Long> i2=foo.<Long>getInner();
^
Consider the following simple example.
public class Foo {
public class FooInner<T> { }
public <T> FooInner<T> getInner() { return null; }
}
public class Bar {
final Foo foo=new Foo();
public Foo.FooInner<Void> i1=foo.getInner(); // incompatible types error on separate compilation
public Foo.FooInner<Long> i2=foo.<Long>getInner(); // incompatible types error on separate compilation
}
If I compile the both files together
$ javac Foo.java Bar.java
they are compiled fine without any errors or warnings (exactly as I expect).
However, if I then compile just Bar.java
$ javac Bar.java
I get the following errors:
Bar.java:4: incompatible types; no instance(s) of type variable(s) T exist so that Foo.FooInner<T> conforms to Foo.FooInner<java.lang.Void>
found : <T>Foo.FooInner<T>
required: Foo.FooInner<java.lang.Void>
public Foo.FooInner<Void> i1=foo.getInner();
^
Bar.java:5: incompatible types
found : Foo.FooInner<java.lang.Long>
required: Foo.FooInner<java.lang.Long>
public Foo.FooInner<Long> i2=foo.<Long>getInner();
^
- duplicates
-
JDK-6356636 Compiler fails to read signatures of inner classes with non-generic outer instance leading to crash
- Closed