record-like initializer for other classes

Brian Goetz brian.goetz at oracle.com
Fri Jun 19 21:55:29 UTC 2020


The attachment was dropped. 

We are interested in generalizing some of the record goodies.  This one is probably one of the weaker ones, but we have thought about it. The basic problem is that in the general case, the parameter names and the field names are essentially unrelated. With records we are able to derive both from a common description.  

In general though, I think there are much higher leverage things to work on here.

Sent from my iPad

> On Jun 19, 2020, at 5:19 PM, Mateusz Romanowski <romanowski.mateusz at gmail.com> wrote:
> 
> Hi,
> Since record classes' concept has become stable, I do hope some ideas might
> be migrated to less-restricted classes.
> 
> I am, I believe, one of many programmers that need to write a lot of
> `this.x = x;`-like assignments in constructors and therefore *used to*
> abuse static methods' inner classes to save some characters.
> 
> Is there any chance to marry inner class' parameter capture with
> record-like class initializer?
> I.e.,  for class with explicit initializer with a _FormalParameterList_:
> * compiler generates implicit or uses compactly declared explicit
> constructor with identical _FormalParameterList_,
> * for any _FormalParameter_ used outside the constructor, compiler captures
> it into implicit final fields *with the same name as parameter*.
> Attached please find some translation equivalencies.
> 
> What do you think?
> 
> Cheers,
> Mateusz R.



More information about the amber-dev mailing list