Method chaining JEP draft

Remi Forax forax at univ-mlv.fr
Sun Mar 24 20:22:01 UTC 2019


Hi Peter,
this has already discussed and rejected under the umbrella of project Coin (for Java 7),
the keywords you are looking for is "chained invocation".

see by example https://stackoverflow.com/questions/1011916/chained-invocation-in-java-7

In the case of builders used to initialize a non-mutable value in a mutable way, like StringBuilder allow to initialize a String, this feature is also related to Java support of the new "withfield" opcode introduced in project Valhalla (for initializing value types).
But given that you are posting on amber-dev, i suppose that you are thinking in term of records, as far as i know, nobody has proposed to have withers (setter that can be chained) for records but the fact that records are non mutable is something relatively new in term of design.

cheers,
Rémi

----- Mail original -----
> De: "JARvis PROgrammer" <mrjarviscraft at gmail.com>
> À: "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Dimanche 24 Mars 2019 20:52:36
> Objet: Method chaining JEP draft

> Hi there,
> At current I am working on a draft for the language feature to allow
> non-static methods to declare themselves as `returning instance on which
> they were called` (a builder pattern is the best illustration of such type
> of methods) making it automatic (rather than forcing the developer to
> use return
> this) or (as another option to be declared by this JEP) to allow such
> behaviour for void methods.
> This is a draft at my local PC (he-he) and Gist at the moment and is only
> under construction but is it at all worth workin on it? This feature seems
> to be an obvious one and might have been discussed in past and yet there
> seems to be no JEP addressed for it.
> 
> So should I continue working on a draft (for discussion here, of course) or
> this was already discussed and there are already existing pros&cons for
> this because of which this feature is not anywhere now?
> 
> Thanks,
> Peter P.


More information about the amber-dev mailing list