> On Jan 27, 2022, at 8:09 AM, Dan Heidinga <heidi...@redhat.com> wrote: > >>> 2) What is the rationale behind the return type restrictions on <new> >>> methods? > .... >> Treatment of <new> methods is still unresolved, so this (and the JEP) is >> just describing one possible approach. I tried to reach a conclusion on this >> a few months ago on this list, but we ended in an unresolved place. I'll try >> again... >> >> Anyway, in this incarnation: the rule is that the return type must be a type >> that includes instances of the current class. So, in class Point, QPoint is >> okay, LObject is okay, but LString is not. > > I don't understand the point of this restriction. Since > Ljava/lang/Object; is acceptable (and has to be), I can use a `<new>` > method to return *any* class but the caller will need to downcast to > use it.
I think the reason we might have some sort of restriction is if we intend for a language or reflection API to be able to rely on these methods having some consistent properties (imagine them being surfaced with java.lang.reflect.Constructor, for example). So think of the restriction as a placeholder ("we may have some sort of restriction on the return type, TBD"). We still need to do some work to figure out the precise requirements, if any.