defaultvalue and enclosing instances

Srikanth srikanth.adayapalam at oracle.com
Wed Sep 19 04:46:05 UTC 2018



On Wednesday 19 September 2018 07:43 AM, Brian Goetz wrote:
> We disallow no arg ctor, right?  So what if the no arg ctor always returns default value, and then you can say outer.new inner()?

Actually ATM, we don't disallow no arg ctors - the following compiles 
fine on Valhalla tip:

__ByValue class Point {
     int x;
     int y;

     Point() {
         x = y = 0;
     }

     Point (int x, int y) {
         this.x = x;
         this.y = y;
     }
}

Srikanth
>
> Sent from my iPad
>
>> On Sep 14, 2018, at 9:26 PM, Srikanth <srikanth.adayapalam at oracle.com> wrote:
>>
>>
>>
>>> On Friday 14 September 2018 09:47 PM, Victor Nazarov wrote:
>>>
>>>
>>> пт, 14 сент. 2018 г., 19:06 John Rose <john.r.rose at oracle.com <mailto:john.r.rose at oracle.com>>:
>>>
>>>     On Sep 14, 2018, at 1:32 AM, Srikanth
>>>     <srikanth.adayapalam at oracle.com
>>>     <mailto:srikanth.adayapalam at oracle.com>> wrote:
>>>     >
>>>     > ... (d) other solutions ...
>>>
>>>     The simplest one comes to mind:  Allow T.default to have a default
>>>     up-reference
>>>     of null, as a special case for inner values.  Referring to the
>>>     outer instance from
>>>     a default inner instance will thus fail with NPE.  "It hurts when
>>>     I do this, Doctor"
>>>     "Then don't do that."
>>>
>>>
>>> But this means that you can't use enclosed value type instances.
>> Not quite. Properly enclosed value instances can be created via the classic constructor notation: e.g:
>> new Outer().new InnerValue();
>>
>> Srikanth
>>



More information about the valhalla-dev mailing list