Add Boolean method to interpret byte value as boolean?

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Feb 20 14:13:52 UTC 2020


Yes - I think 0 == false has enough mathematical backing which would 
make sense to add it, IMHO. Other APIs do it too [1].

Also, if we had such a method, we could use it to adapt a byte returning 
VarHandle/MethodHandle into a boolean returning one.

Maurizio

[1] - 
https://commons.apache.org/proper/commons-lang/javadocs/api-2.4/org/apache/commons/lang/BooleanUtils.html#toBoolean(int)

On 20/02/2020 13:56, Ty Young wrote:
> Hi,
>
>
> Many functions use boolean values to determine whether or not an 
> operation succeeded(true) or failed(false). Project Panama does not 
> actually see booleans however and instead interprets them as byte 
> values(which is technically correct). This means that in order to 
> convey the correct type as defined in C, you would need to do your own 
> check to see if the value is 1.
>
>
> There isn't, however, a standard method of doing this. Boolean only 
> has a function for getting a boolean from a string, not a byte. Given 
> that the need to convert a byte value to a boolean will be more common 
> with Project Panama it seems appropriate that one be added.
>
>
> Could this be done?
>
>


More information about the panama-dev mailing list