RFR:JDK-8198749 Translation of value constructors in classic constructor notation

Remi Forax forax at univ-mlv.fr
Thu Jul 12 07:45:46 UTC 2018


----- Mail original -----
> De: "John Rose" <john.r.rose at oracle.com>
> À: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>
> Cc: "valhalla-dev" <valhalla-dev at openjdk.java.net>
> Envoyé: Jeudi 12 Juillet 2018 02:18:05
> Objet: Re: RFR:JDK-8198749 Translation of value constructors in classic constructor notation

[...]

> (Along those lines, I *also* suspect that *value* class constructors should be
> allowed to *return a value*, which is the short-circuited result of the constructor.
> Thus, if the constructor decides that the client is really asking for a pre-existing
> value X, it can just say "return X" and that's what the client will get.  If such a
> constructor says plain "return" with no value, or drops off of the end of the
> block, then of course the value implied by the current field settings—which must by DA
> before the return—is what the client gets.  But I'm not pressing this thought
> too hard yet.  I'm concentrating on "codes like class", more than on "look how values
> are so different from objects".)

I will prefer not too allow (value) class constructor to return a value, it's what <make> factory method are for.

I think it's better to:
- allow <make> factory method for value and reference that returns a value/reference of any type.
- have value class constructor automatically translated to <make> factory method by the compiler.
- make <init> constructor and <make> factory mutually exclusive.

Rémi


More information about the valhalla-dev mailing list