Skip to content

Improve support for Java varargs methods #469

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

Open
slavchev opened this issue Jun 3, 2016 · 5 comments
Open

Improve support for Java varargs methods #469

slavchev opened this issue Jun 3, 2016 · 5 comments

Comments

@slavchev
Copy link

slavchev commented Jun 3, 2016

Java supports varargs methods. For example, [Class.getMethod](https://developer.android.com/reference/java/lang/Class.html#getMethod%28java.lang.String, java.lang.Class<?>...%29)

Method getMethod (String name, Class...<?> parameterTypes)

This is syntax sugar for the actual method signature which is

Method getMethod (String name, Class<?>[] parameterTypes)

Currently, NativeScript for Android does not support calling such method with implicit parameter

var klass = java.lang.Object.class;

// option 1) not supported
var method = klass.getMethod("hasCode");

// option 2) supported
var method = klass.getMethod("hasCode", null);

We can provide another implementation for the current method resolution algorithm so it tries to find a method with one additional parameter (array) as a fallback and if this fail then the method resolution fails as expected.

@petekanev
Copy link
Contributor

Is this related to #67 ?

@slavchev
Copy link
Author

slavchev commented Jun 3, 2016

Yes, it is the same issue. Good catch!

@govi2010
Copy link

I have JAVA class which use for varargs

https://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html

How i can use that in TypeScript I am working on plugin development.

@petekanev
Copy link
Contributor

@govi2010 is there related JavaScript/TypeScript code with your inquiry?

I believe we went through the issue together on Slack, and figured out that 1) The wrong method was being invoked, and 2) parameters to a varargs method need to first be put in a javascript array

var data = [com.linkedin.platform.utils.Scope.R_BASICPROFILE, com.linkedin.platform.utils.Scope.R_EMAILADDRESS];
var scope = com.linkedin.platform.utils.build(data);

Ref to Slack discussion in the #android channel: https://nativescriptcommunity.slack.com/messages/C0MMFBJNR/convo/C0MMFBJNR-1517039657.000009/?

@govi2010
Copy link

@Pip3r4o Yes You are correct. Thank you man

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

No branches or pull requests

5 participants