Inline Classes and extends

Stephen Colebourne scolebourne at joda.org
Tue Dec 10 21:08:25 UTC 2019


Is there any hope of rescuing superclass cases by converting the superclass
to an interface?

I'm particularly thinking of java.time.ZoneId and it's subclasses
ZoneRegion and ZoneOffset. ZoneId had to be an abstract class originally as
there were no sealed types, but it could be converted to a sealed interface
in the future if that was a compatible change. Then the two subclasses
could be inline classes (which they logically are). It also assumes we can
have package scoped inline classes.

I ask because the plan to convert the primitive box types to interfaces
suggests ZoneId could be another candidate.

Stephen


On Tue, 10 Dec 2019, 18:24 John Rose, <john.r.rose at oracle.com> wrote:

> On Dec 10, 2019, at 10:17 AM, August Nagro <augustnagro at gmail.com> wrote:
> >
> > One question I have is about `extends`. I understand that inline classes
> cannot extend IdentityClass, but what about other inline classes? I have a
> lot of classes that would make sense as inline, but are held back by their
> superclass (which also could be inline).
>
> One thing you get with the extra indirection of reference objects
> is layout polymorphism, the power to have one type which points
> at two or more distinct layouts.
>
> If you get rid of the pointer (which is a must for inlines, so they
> can “work like an int”), then you also lose the ability to represent
> layout polymorphism.
>
> It’s like in C++ when you try to mix inheritance and by-value storage
> of instances:  Stuff goes wrong, awkwardly.
>
> struct A { int x; }
> struct B : public A { int y; }
> A avar; avar.x = 1;
> B bvar; bvar.x = 2; bvar.y = 3;
> A anotheravar = bvar;  // what happened to the 3??
>
> — John


More information about the valhalla-dev mailing list