Java interop for primitive types #1502
tonygermano
started this conversation in
General
Replies: 1 comment 1 reply
-
Also see #996 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I was creating PR #1501 I noticed a couple things that I thought were worthy of bringing up for discussion.
char
Java
char
gets converted to a jsnumber
, but whenisJavaPrimitiveWrap
is false in the Context's WrapFactory,java.lang.Character
gets converted to a jsstring
instead. This seems inconsistent, but it's been this way forever.long
Java
long
gets converted to anumber
, and likewise whenisJavaPrimitiveWrap
is false,java.lang.Long
also gets converted to anumber
(see below for some quirks regarding this.) This causes a java widening conversion to occur, and an unavoidable loss of precision when the value is outside of the range of[Number.MIN_SAFE_INTEGER - Number.MAX_SAFE_INTEGER]
. This can make it challenging to impossible to work with classes likejava.util.UUID
.Now that we have
BigInt
support, which obviously did not exist when this class was first written, I wonder if we should give the option to convertlong
tobigint
so that Rhino can support true 64-bit integer interop with java. I think it would make sense to do this as a WrapFactory flag likeisJavaPrimitiveWrap
. Likewise, I think bigint values should be automatically truncated (by calling BigInteger::longValue) when passed to java methods requesting along
.Here are the current quirks I mentioned:
Beta Was this translation helpful? Give feedback.
All reactions