-
Enhancement
-
Resolution: Unresolved
-
P5
-
None
-
6
-
generic
-
generic
Yes, this is allowed, but this useful warning is telling you that when you override and omit the varargs syntax, the resulting class is not substitutable for the superclass because code that invokes the superclass method using varargs won't work with the subclass. We originally made this an error for this reason, but then changed it to only a warning (not even a mandated one) and not an error to allow retrofitting existing interfaces with varargs. It appears the diagnostic was not suitably modified, though.
-Neal
On 12/13/06, ... wrote:
On this case:
interface A {
void f(boolean ... x);
void g(short[] x);
}
class B implements A {
public void f(boolean ... y) {}
public void g(short[] y) {}
}
class C implements A {
public void f(boolean[] x) {}
public void g(short ... x) {}
}
class D {
A a1 = new B();
A a2 = new C();
}
t.java:20: warning: g(short...) in C cannot implement g(short[]) in A; overridden method has no '...'
public void g(short ... x) {}
^
t.java:19: warning: f(boolean[]) in C cannot implement f(boolean...) in A; overriding method is missing '...'
public void f(boolean[] x) {}
^
But despite those warnings the methods in C do seem to implement the declarations in A.
The JLS says that "T ..." is treated as "T[]" so it would seem that the C methods should be able to implement the A declaration. Is that your understanding?
-Neal
On 12/13/06, ... wrote:
On this case:
interface A {
void f(boolean ... x);
void g(short[] x);
}
class B implements A {
public void f(boolean ... y) {}
public void g(short[] y) {}
}
class C implements A {
public void f(boolean[] x) {}
public void g(short ... x) {}
}
class D {
A a1 = new B();
A a2 = new C();
}
t.java:20: warning: g(short...) in C cannot implement g(short[]) in A; overridden method has no '...'
public void g(short ... x) {}
^
t.java:19: warning: f(boolean[]) in C cannot implement f(boolean...) in A; overriding method is missing '...'
public void f(boolean[] x) {}
^
But despite those warnings the methods in C do seem to implement the declarations in A.
The JLS says that "T ..." is treated as "T[]" so it would seem that the C methods should be able to implement the A declaration. Is that your understanding?