Rewriting `d1` like this makes it a proper singlet...
# announcements
s
Rewriting
d1
like this makes it a proper singleton (type === value) and your error goes away.
Copy code
object d1 : java.util.Date() { // d1 is of type d1, which is a sub-type of java.util.Data
    val test = 5
}
Still, why would a local val allows access to
test
but a top/global one not…. not sure đŸ™‚
z
I think it might be a JVM/bytecode thing. This code works too:
Copy code
class Test {
  public void test() {
    new Date() {
      public String fooBar() {
        return "foo bar";
      }
    }.fooBar();
  }
}
But there’s no way to do that at a higher level since java requires explicit types.
s
Thanks JVM!!! đŸ˜›