I just encountered a behavior I first thought it was a bug in Eclipse. Consider this simple class:
public class Foo {
public static interface Callback {
public void onAction();
}
}
This is perfectly valid. However, this isn't:
public class Foo implements Callback {
public static interface Callback {
public void onAction();
}
public void onAction() { /*some implementation*/ }
}
But this is valid, too:
public class Foo {
public static interface Callback {
public void onAction();
}
private final Callback mCallback = new Callback() {
public void onAction() { /*some implementation*/ }
};
}
Why does Java force me to kind of 'waste' a member for it, if it could simply save it by letting me implement this itself? I'm well aware of the 'workaround' to put this interface in its own file, but out of curiosity: Is there a reason why this won't work?