-
Notifications
You must be signed in to change notification settings - Fork 2
add @static support for extension method #168
Comments
To clarify, currently in Dotty, |
@hepin1989 you can already achieve what you want, without using |
Is |
@LPTK What if the type is defined in Java? |
It's completed but not documented, it's going to be part of Scala 3. |
@hepin1989 hmm... then I guess you're out of luck. But that's quite a niche use case, and I'm not sure it warrants special support. |
In my opinion it isn't, for example if I write: object Test {
@static val foo: Int =
List(1,2,3).reduce(_ + _)
} The generated code does contain a static field foo in class Test, but the body of this field ends up calling a lambda defined in |
I missed the context when |
refs :Kotlin/KEEP#347 |
some recent discussion at https://contributors.scala-lang.org/t/scala-3-extension-method-for-object-and-java-class/6135 |
Re extension methods for java "companion objects": I think this could fairly easily be made to work once you have erased definitions. The problem is that extension (erased a: String.type) def hello = "I am String" Now you should be able to call
Could even be made more ergonomic if the compiler would define all java “companion objects” as instances of erased classes. Then you as a user don’t need to think about adding erased or not. In a way java companion objects have always been "erased". So would be cool to build that on top of first class |
Dotty now has extension method support : https://dotty.epfl.ch/docs/reference/contextual/extension-methods.html
and Dotty is adding
@static
support too, can we add static support for extension method so we can addfactory
like methods to the origin type.Dart has an issue for this too:dart-lang/language#723
The text was updated successfully, but these errors were encountered: