hfhbd
04/04/2024, 3:51 PMclass Foo {
companion object {
val s = "foo"
}
}
results into Foo.Companion.s
but the static field Companion
clashes with the class Companion
resulting in Companion::class.s
and an unresolved member s
due Groovy class syntax.Kirill Grouchnikov
04/04/2024, 3:57 PM<mailto:Foo.@Companion.xyz|Foo.@Companion.xyz>
?hfhbd
04/04/2024, 3:58 PMhfhbd
04/04/2024, 3:58 PMKirill Grouchnikov
04/04/2024, 3:58 PMVampire
04/04/2024, 4:10 PM.@
in Groovy means "access the field with that name directly".
If you for example have a property that consist of a field "foo" and a getter "getFoo", then in Groovy using .foo
will call the getFoo
getter, but with .@foo
you can directly access the field without going through the getter.
Same works here for the companion object to access the static field called Companion
instead of the nested class called Companion
.hfhbd
04/04/2024, 4:15 PMFoo.Companion.s
does work when you don't use CompileStatic
, but I want to enable it.