Java allows me to define local abstract classes, like in this example:
public class Foo {
public void foo() {
abstract class Bar { // Bar is a local class in foo() ...
abstract void bar();
}
new Bar() { // ... and can be anonymously instantiated
void bar() {
System.out.println("Bar!");
}
}.bar();
}
}
For some reason, when I try to define a "local interface" instead of the local class, like this:
public class Foo {
public void foo() {
interface Bar { // Bar was supposed to be a local interface...
void bar();
}
new Bar() { // ... to be anonymously instantiated
void bar() {
System.out.println("Bar!");
}
}.bar();
}
}
Java complains that "The member interface Bar can only be defined inside a top-level class or interface". Is there a reason for this? Or am I missing a mistake I made?