Add Boolean method to interpret byte value as boolean?
Ty Young
youngty1997 at gmail.com
Thu Feb 20 16:02:46 UTC 2020
On 2/20/20 8:13 AM, Maurizio Cimadamore wrote:
> Yes - I think 0 == false has enough mathematical backing which would
> make sense to add it, IMHO. Other APIs do it too [1].
Would 0 == false be a safe implementation of such a method?
Hypothetically if whatever command line switch was passed that allows
"dirty" memory, I imagine that this could cause issues since dirty
memory could be interpreted as true. Boolean.valueOf(<String>) also
checks for true instead of false.
>
> Also, if we had such a method, we could use it to adapt a byte
> returning VarHandle/MethodHandle into a boolean returning one.
That would be nice!
>
> 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