Object REXX and Java 17: Resolving Overloaded Methods with Primitive Arguments
0 reputation · 28 Jan 2022, 19:31 UTC
0 reputation · 28 Jan 2022, 19:31 UTC
When integrating Object REXX with Java 17 via jinit, method dispatch for overloaded Java methods accepting primitive types creates a boundary. REXX variables are untyped, so passing a numeric literal to a method expecting int or double does not communicate the required Java type to the dispatcher. Documented behavior indicates explicit wrapper instantiation or type coercion is necessary, but the boundary between REXX coercion rules and Java overload resolution remains a design concern.
Version assumptions add complexity. OpenObject REXX 5.0+ supports Java 17 classpaths natively, while legacy distributions constrained to Java 8 may encounter module-path loading failures. This split raises questions about whether primitive mapping behavior is consistent across REXX-Java combinations or whether dispatcher logic changed between Java 8 and 17 runtimes.
For developers calling overloaded Java APIs from execs, the practical uncertainty is how to ensure deterministic overload selection when REXX passes untyped values. Without clear rules, the same exec may resolve to different signatures depending on REXX version, Java version, or the presence of String versus StringBuilder parameters.
Does Object REXX 5.0+ on Java 17 require explicit wrapper classes for primitive arguments in all overloaded contexts, or does native coercion cover int and double reliably? Are checked Java exceptions thrown during primitive-argument dispatch consistently converted to REXX RuntimeException, or does trap behavior vary by distribution? How should execs avoid ambiguous overload resolution when a Java class exposes both String and StringBuilder variants alongside primitive overloads?
35275 reputation · 29 Jan 2022, 04:23 UTC
int, long, double) to map the value to.
In Object REXX 5.0+, while native coercion handles many basic cases, it is not always deterministic when multiple overloads exist. If a Java class provides both process(int) and process(double), passing a REXX numeric literal may resolve differently depending on the internal state of the dispatcher or version, leading to inconsistent behavior across different runtime environments.
To ensure the correct method is invoked and avoid runtime exceptions, follow these practices:
; val = 10; myObject.method(Integer(val));
String and StringBuilder variants alongside primitive overloads, as the REXX-to-Java conversion rules for these types can be complex during automated dispatch.Regarding errors, checked Java exceptions thrown during primitive dispatch are generally converted to a REXX RuntimeException. However, the specific trap behavior—whether it triggers a SIGNAL or terminates the exec—can vary based on how the REXX distribution handles the Java stack trace.
These assumptions assume you are using Object REXX 5.0+ on a Java 17 runtime. Older distributions restricted to Java 8 will not encounter module-path issues but may also exhibit different primitive mapping logic due to the older JVM dispatcher behavior.
To verify how your specific environment resolves an overload, run a test exec with a controlled Java class:
; Test class has methods test(int) and test(double)
t = new TestClass();
nt.test(5);
t.test(5.5); Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 28 Jan 2022, 22:35 UTC
To resolve ambiguity in overloaded Java methods, it is important to note that Object REXX typically treats numeric values as floating-point by default. When a Java class exposes both int and double signatures, the jinit dispatcher may not align with the developer's intent, as REXX lacks explicit primitive type markers.
The most reliable way to ensure deterministic overload selection is to bypass implicit coercion by explicitly instantiating Java wrapper classes. For example:
java.lang.Integer for int signatures.java.lang.Double for double signatures.This approach removes the reliance on the bridge's internal priority rules. Additionally, when targeting Java 17, verify that the JVM is started with the necessary --add-opens flags; otherwise, the reflection-based dispatch used by the REXX bridge may encounter InaccessibleObjectException due to strong encapsulation of Java internals.