Braces should be optional for object expressions

In many cases, an object expression is used to override functionality:

val o = object : SomeInterface {
    override fun doSomething() {
        println("Hello!")
    }
}

However, when using an object expression to extend an abstract class (that has no abstract members remaining) the braces can be extraneous when you’re not overriding anything:

val o = object : SomeAbstractClass() {
    // nobody's home
}

I propose that the object expression braces be made optional, such that when there are no member definitions needed for a valid object expression, they can be omitted:

val o = object : SomeAbstractClass()

Thanks!

3 Likes

In cases like these, wouldn’t it make sense to make SomeAbstractClass an open, non-abstract class? There aren’t any abstract members, and that way it can be instantiated without an object expression.