-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
6
-
generic
-
generic
Tried in windows. JDK 1.6.0-ea-b32
Compiler throws misleading error report when interface method implemented in anonymous inner class.
Please see the following code:
<code>
interface Foo{
public void bar();
}
public class TestInterface {
Foo foo = new Foo() {
public void notBar(){
System.out.println("Bar...");
}
};
}
</code>
Output of the code when compiled:
<output>
E:\javatrails\compilerAPI>javac -Xlint TestInterface.java
TestInterface.java:7: <anonymous TestInterface$1> is not abstract and does not o
verride abstract method bar() in Foo
public void notBar(){
^
1 error
</output>
The error pointer is wrong and misleading.
I think the following will be more meaningful.
Foo foo = new Foo() {
^
If I remove the methods decalration then compiler will not throw any line number
<code>
interface Foo{
public void bar();
}
public class TestInterface {
Foo foo = new Foo() {
};
}
</code>
<output>
E:\javatrails\compilerAPI>javac -Xlint TestInterface.java
error: <anonymous TestInterface$1> is not abstract and does not override abstrac
t method bar() in Foo
1 error
</output>
Compiler throws misleading error report when interface method implemented in anonymous inner class.
Please see the following code:
<code>
interface Foo{
public void bar();
}
public class TestInterface {
Foo foo = new Foo() {
public void notBar(){
System.out.println("Bar...");
}
};
}
</code>
Output of the code when compiled:
<output>
E:\javatrails\compilerAPI>javac -Xlint TestInterface.java
TestInterface.java:7: <anonymous TestInterface$1> is not abstract and does not o
verride abstract method bar() in Foo
public void notBar(){
^
1 error
</output>
The error pointer is wrong and misleading.
I think the following will be more meaningful.
Foo foo = new Foo() {
^
If I remove the methods decalration then compiler will not throw any line number
<code>
interface Foo{
public void bar();
}
public class TestInterface {
Foo foo = new Foo() {
};
}
</code>
<output>
E:\javatrails\compilerAPI>javac -Xlint TestInterface.java
error: <anonymous TestInterface$1> is not abstract and does not override abstrac
t method bar() in Foo
1 error
</output>
- duplicates
-
JDK-6253161 Incorrect position of serial warning in anonymous class
-
- Closed
-
- relates to
-
JDK-6320556 Bad position for anonymous class
-
- Closed
-