Declaring a method when creating an object

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();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)