My experience with Sealed Types and Data-Oriented Programming

Jens Lideström jens.lidestrom at fripost.org
Sat Sep 17 06:22:58 UTC 2022


On 2022-09-09 20:46, John Rose wrote:
> This feels like it /might/ be a simple oversight. If so we might choose to fix it. Or it might well be a conscious decision to limit the impact of reflection on the language proper. The sharpening of |String.class| to |Class<String>| actually requires complicated moves in the heart of the language, the JLS; such moves are very expensive. Addressing this one would require JLS surgery.

I don't think this applies to Class#getPermittedSubclasses. I think that method could just propagate the type parameter of Class. The magic of String.class is not needed.

The cast in David Alayachew's code could simple be moved into getPermittedSubclasses, and the result type changed:

public Class<T>[] getPermittedSubclasses() {
     ...
     return (Class<T>[]) subClasses;
}

Best regards,
Jens Lideström


More information about the amber-dev mailing list