alternatives or complements to layers

Peter Levart peter.levart at gmail.com
Wed Jan 7 16:36:46 UTC 2015


On 01/07/2015 04:39 PM, Maurizio Cimadamore wrote:
>
> On 07/01/15 15:37, Peter Levart wrote:
>> It was said that an option is for all value types (including 
>> primitives) to get 3 Object methods (hashCode, equals, toString). So 
>> at least println is doable. 
> Right - I was speaking more generally of all methods which are 
> overloaded on the parameter type with Object, int, long, ...
>
> Maurizio

Depends on how value types interact with interfaces. I think that the in 
following idiom, for example:


interface SomeInterface {  method() { ...  } }


<any T> void doSomething(T arg) {
     if (arg instanceof SomeInterface) {
         ((SomeInterface)arg).method(); ...
     }
}


It would not be necessary to box the 'arg' (in specializations where T 
is value type) just to invoke an interface method on it. The expression 
"arg instanceof SomeInterface" could be evaluated at specialization time 
and replaced with either "true" or "false".

The cast ((SomeInterface)arg) could be replaced during specialization 
with either "throw CCE" or no-op.

So value types could expose common behaviour (like Formattable, etc...) 
even to "any T" methods without resorting to boxing (which 
specialization is trying to avoid).



Peter




More information about the valhalla-dev mailing list