__WhereVal/__WhereRef on fields

Brian Goetz brian.goetz at oracle.com
Wed Dec 16 17:49:15 UTC 2015

To put this in perspective, you can do anything with refs that you can 
do with values, and more (assign to null, synchronize on them, etc.)  So 
rather than thinking in terms of "here's the value version, and here's 
the ref version", its more effective to think in terms of "here's the 
any version (that works for values and refs)" and "here's the 
optimized/specialized version for refs". (In other words, __WhereVal is 
not needed and is probably going away as part of the model.)

At which point, being able to __WhereRef on a field is purely a space 
optimization -- you're free to declare the field and not use it.  Hence, 
its a low priority to support that at this stage.

On 12/16/2015 12:43 PM, Brian Goetz wrote:
> It definitely does not currently do so.
> Not clear whether this will be part of the eventual model or not -- 
> still figuring out the pros and cons of this.
> On 12/16/2015 12:37 PM, Ali Ebrahimi wrote:
>> Hi,
>> Is compiler supposed to handle restrictions on fields?
>> public class Main {
>>      public static class Test<any T>{
>>          public __WhereVal(T) int x;
>>          public __WhereRef(T) long x2;
>>      }
>>      public static void main(String[] args) {
>>          Test<int> ti = new Test<int>();
>>          long p = ti.x2; //<=======================
>>      }
>> }

More information about the valhalla-dev mailing list