Superclasses with fields
-
liangchenblue at gmail.com
Tue Aug 22 00:30:29 UTC 2023
I think Thiago has a good point: this abstract class with fields scenario
may look like what we will encounter when we implement generic
specialization: the erased type acts like a superclass and the
parameterized types (with value types, especially) act like subclasses. I
think such a model is also why JEP 181 was introduced. Why can't these 2
processes share at least some of their logic? How are we going to implement
generic specialization otherwise?
> 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.
Isn't this already in the language model, that if an abstract class is not
identity (either implicitly or explicitly, such as by declaring
synchronized methods, etc.), then it belongs to such a category? Do we need
another category to "push down" the fields for only some of these
non-identity classes, once the non-identity requirements are relaxed, to
avoid the performance overhead?
Chen Liang
On Tue, Aug 22, 2023 at 2:54 AM Brian Goetz <brian.goetz at oracle.com> wrote:
> 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> <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/20230822/e19e3a81/attachment.htm>
More information about the valhalla-spec-observers
mailing list