Extension methods

Johannes Spangenberg johannes.spangenberg at hotmail.de
Sun Apr 28 12:25:11 UTC 2024


> I would just like to express some of my concerns regarding pipe 
> operator ( |> syntax ).

I agree that the pipe operator proposed for JavaScript feels a bit 
alien. It also doesn't mix well with normal method calls. So, I also 
wouldn't take it as is. I just thought it might be interesting that 
there were related discussions in another community already, as they 
might get relevant if such solution would be considered for Java.

> Regarding traits, I am not an expert in functional programming, but 
> what catches my eye right away is that, as I understand, this approach 
> is incompatible with var keyword.

While I was just assigning the objects to a variable, I think that is 
not a common use case. It was just the most simple use case I could 
think of, which demonstrates the behavior. The var-keyword would 
continue to resolve to the most specific type known, i.e. Path and 
List<Path>. (Just as the `var` in `var x = new ArrayList()` resolves 
into ArrayList, not List.)

I think the most common use cases for Traits, just as for unions, would 
be in parameters. For example, consider the Gradle API of 
Project.files(Object...).

    https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#files-java.lang.Object...-

Anyway, also note that Traits would probably deserve there own 
discussion, if actually considered. I just wanted to mention them 
because when implemented as Rust, they provide a solution for extension 
methods which can be considered superior to the solutions of Kotlin and 
some other languages. However, I am not actually a fan of extension 
methods in Java, as mentioned in my previous email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240428/6ac9bf99/attachment.htm>


More information about the amber-dev mailing list