java.lang.Object
has no a
methods declared (2), while the anonymous class returned by the class instance creation expression new Object() { public void a() {} }
does (1).
Use Java 10’s local variable type inference (var
) to make the second option as valid as the first one.
var object = new Object() {
public void a() {}
};
object.a();