EVALUATION
The submitter is correct. Quoting the JLS:
15.9.5 Anonymous Class Declarations:
... "An anonymous class is always implicitly final (8.1.1.2)."
5.5 Casting Conversion
... "compile-time reference type S (source) to a compile-time reference
type T (target)." ...
... "If T is an interface type" ...
"If S is a final class (8.1.1), then S must implement T, or a compile-time
error occurs."
The problem appears to be that the compiler don't mark anonymous classes
final.
###@###.### 2005-1-21 09:21:15 GMT
We should fix this in mustang. No apparent need for backport to JDK 5.
###@###.### 2005-1-21 20:05:33 GMT
|
SUGGESTED FIX
Index: src/share/classes/com/sun/tools/javac/comp/Check.java
============================================================
@@ -597,9 +597,13 @@
case TYP:
if (sym.isLocal()) {
mask = LocalClassFlags;
+ if (sym.name.len == 0) { // Anonymous class
// Anonymous classes in static methods are themselves static;
// that's why we admit STATIC here.
- if (sym.name.len == 0) mask |= STATIC;
+ mask |= STATIC;
+ // JLS: Anonymous classes are final.
+ implicit |= FINAL;
+ }
if ((sym.owner.flags_field & STATIC) == 0 &&
(flags & ENUM) != 0)
log.error(pos, "enums.must.be.static");
###@###.### 2005-1-21 19:58:58 GMT
|