JDK-6343995 : "incompatible types" error when files are compiled separately
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2005-10-31
  • Updated: 2010-04-02
  • Resolved: 2005-12-30
Related Reports
Duplicate :  
Description
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();
^

Comments
EVALUATION I have closed this as a duplicate of 6356636 as that bug has more information.
30-12-2005

EVALUATION The information in the class file appears to be correct. Most likely a problem in javac's class reader.
02-12-2005