Fwd: Superclasses with fields

Brian Goetz brian.goetz at oracle.com
Mon Aug 21 16:39:26 UTC 2023


The below was received on the valhalla-spec-comments list.

The topic of further relaxing the restrictions on abstract class 
supertypes of value classes has been discussed by the EG.  While it is 
possible that such restrictions could be further relaxed, we are likely 
facing diminishing returns.

It is certainly possible to define a way that fields and initialization 
logic from an abstract super is "copied" into the value class.  But this 
would still come with restrictions we might not like; we would then 
either have to give up putting fields in the value subclass (to 
eliminate layout polymorphism), or give up flattening of the abstract 
class type (because there is layout polymorphism.)  And, we would likely 
end up creating a new category of abstract class to support the "pushing 
down" of fields and initialization, which is new language complexity. 
Overall this seems like something that has a relatively weak 
return-on-complexity and there are many opportunities for much higher 
return right now.


-------- Forwarded Message --------
Subject: 	Superclasses with fields
Date: 	Mon, 21 Aug 2023 08:03:58 -0300
From: 	Thiago Henrique Hupner <thihup at gmail.com>
To: 	valhalla-spec-comments at openjdk.org



Now that most of the migration issues from classes to value classes have 
been discovered, would it also be possible to allow maybe a subset of 
superclasses that contains some fields?

Probably having "value enums" would be great, but also it would enable 
to have subclasses of j.u.AbstractList to also become value classes.

Probably there are more issues to it than I could remember, but wouldn't 
it be possible to check at load time if the superclass uses some 
unsupported features, like synchronized methods, and throw an error?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-observers/attachments/20230821/b3e94775/attachment.htm>


More information about the valhalla-spec-observers mailing list