SoV-3: constructor questions

Dan Smith daniel.smith at oracle.com
Thu Jan 27 23:59:27 UTC 2022


> On Jan 27, 2022, at 8:09 AM, Dan Heidinga <heidinga at 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.



More information about the valhalla-spec-observers mailing list