inconsistent generic types behaviour when compiling together vs. separate
Vicente-Arturo Romero-Zaldivar
vicente.romero at oracle.com
Mon Feb 3 04:34:39 PST 2014
Hi Peter,
Thanks for the report. I have created:
https://bugs.openjdk.java.net/browse/JDK-8033437 to track this issue.
Vicente
On 29/01/14 14:59, Peter Levart wrote:
> Here's an example:
>
> Create an empty directory and copy into it the following two sources:
>
> Ref.java:
>
> public class Ref<T> {
> final RefQueue<? super T> queue = new RefQueue<>();
>
> public static void main(String[] args) {
> Ref<Object> r = new Ref<>();
> RefQueue<Object> q = r.queue;
> }
> }
>
> RefQueue.java:
>
> public class RefQueue<T> {
> }
>
> Then execute:
>
> mkdir out
> javac -d out Ref.java
>
> This compiles fine and produces two class files in out directory:
>
> Ref.class
> RefQueue.class
>
> Now do the following:
>
> rm RefQueue.java
> mkdir out2
> javac -cp out -d out2 Ref.java
>
> Which produces compile-time error:
>
> Ref.java:6: error: incompatible types: RefQueue<CAP#1> cannot be
> converted to RefQueue<Object>
> RefQueue<Object> q = r.queue;
> ^
> where CAP#1 is a fresh type-variable:
> CAP#1 extends Object super: Object from capture of ? super Object
> 1 error
>
>
> It seems that the behaviour is inconsistent. There's also a question
> whether the compile-time error is a correct behaviour or not. I tried
> this with JDK 7u51, JDK 8 ea-b121 and recent JDK 9 from dev forest.
> They all behave the same.
>
>
> Regards, Peter
>
More information about the compiler-dev
mailing list