I noticed I get an error `Expected a class body` i...
# getting-started
j
I noticed I get an error
Expected a class body
if I do this. Is this intended?
Copy code
open class Test
val test = object : Test()
It seems to want an empty body afterwards.
v
Well, at least it is either an implementation bug or specification bug I'd say. https://kotlinlang.org/spec/expressions.html#object-literals - if I don't get it wrong - allows to have no body. But the examples and implementation enforce one.
From a quick look I'd say even the provided antlr grammer would allow having no body
j
Allowing no body would be consistent with the other aspects of the language. Interesting.
After some thought, I think it's a spec error.
Copy code
val test = object : Test() {}
is effectively equivalent to
Copy code
val test = Test()
So why use an anonymous object at all if you're not going to give it body? I think that's the idea.
v
val test = object : Test(), Whatever
Or if
Test
is abstract but does not have abstract members
j
Ah, yeah. That is a more compelling case than what I originally wrote.