Strict long type casting

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Apr 7 01:12:42 UTC 2020


Hi Ty,
I'd need to have a look at the code of MemoryNumber/MemoryLong to 
understand what's going on.

Thanks
Maurizio

On 07/04/2020 01:49, Ty Young wrote:
> Hi all,
>
>
> I'm trying to create a way of reading primitive number based struct 
> values(since VarHandle.get is polymorphic) by combining Java's Number 
> abstract class with my abstraction like so:
>
>
> public abstract class MemoryNumber<E extends Number> extends Number 
> implements MemoryValue<E>
>
>
> Which is then extended by classes like "MemoryLong".
>
>
> The problem here is that with long(and only long) the type casting is 
> strict and fails. Attempting to call byteValue() fails on intValue(). 
> This doesn't, for whatever reason, happen with normal on-heap long 
> values nor does it happen with an MemoryInt implementation either.
>
>
> I tried looking in the source code of Long.class and I couldn't find 
> anything that I was doing differently besides using Panama, so I'm a 
> bit lost here. Does anyone know what's going on?
>


More information about the panama-dev mailing list