Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve overloaded method invocation when null is passed. #1352

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rPraml
Copy link
Contributor

@rPraml rPraml commented Jul 6, 2023

Problem

We often have to deal with overloaded methods like

void setValue(String value)
void setValue(Object value)

When invoking such methods from rhino, everything is fine, as long as the value is not undefined or null

v.value = 123; // will call setValue(Object)
v.value = "foo"; // will call setValue(String)
v.value = null; // will fail with ambiguous method call

Currently, there's no way to pass null to an overloaded value, as javascript cannot determine, which method should be called.

Possible fix

Adjusting the conversion weight for JSTYPE_UNDEFINED and JSTYPE_NULL:
Converting them to String should weight less than converting them to Object (this means, that setValue(String) will be preferred)

Note and room for discussion

I know, the choiche to favor String over Object is closely related to our use-case (and I'm OK if we can find a consent in which order such conversion should happen)

What I really want is to invoke overloaded methods with "null" values.
Unfortunately I cannot do a setValue((String)null) or setValue((Object)null) in javascript

It may be possible to construct some hacky null type for java classes (e.g. String.null Integer.null and so on)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant