java - Nashorn: How to select constructor to invoke - Stack Overflow

I know from this page that I can select a method like this:API["test(Integer[])"](1);How do I

I know from this page that I can select a method like this:

API["test(Integer[])"](1);

How do I do this for constructors? In particular, I'm trying to instantiate a java.awt.Color from Nashorn:

var highlightColor = new java.awt.Color(1, 1, 128/255, 1);

I get the following error: Can't unambiguously select between fixed arity signatures [(float, float, float, float), (int, int, int, int)] of the method java.awt.Color. for argument types [java.lang.Integer, java.lang.Integer, java.lang.Double, java.lang.Integer]

I've tried this:

var highlightColor = new java.awt.Color["(float,float,float,float)"](1, 1, 128/255, 1);

But that gives me this error: Caused by: :52 TypeError: null is not a function

I know from this page that I can select a method like this:

API["test(Integer[])"](1);

How do I do this for constructors? In particular, I'm trying to instantiate a java.awt.Color from Nashorn:

var highlightColor = new java.awt.Color(1, 1, 128/255, 1);

I get the following error: Can't unambiguously select between fixed arity signatures [(float, float, float, float), (int, int, int, int)] of the method java.awt.Color. for argument types [java.lang.Integer, java.lang.Integer, java.lang.Double, java.lang.Integer]

I've tried this:

var highlightColor = new java.awt.Color["(float,float,float,float)"](1, 1, 128/255, 1);

But that gives me this error: Caused by: :52 TypeError: null is not a function

Share Improve this question edited May 23, 2017 at 11:59 CommunityBot 11 silver badge asked Dec 9, 2014 at 21:23 David StruckDavid Struck 1572 silver badges9 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

We added this functionality, but it will only be available with Java 8u40. The exact syntax is java.awt["Color(int, int, int)"] (the signature is part of the last name ponent, consistent with how it works on method names). You can try it out with early access releases of 8u40 at this time (it's scheduled for release in March 2015).

You need to make sure you're passing in 4 integers (or floats in this case), try this.

var highlightColor = new java.awt.Color(1.0, 1.0, 128/255, 1.0);

Pass either 4 ints or 4 floats

var highlightColor = new java.awt.Color(255, 255, 128, 255);

OR

var highlightColor = new java.awt.Color(1.0, 1.0, 128/255, 1.0);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745525639a4631457.html

相关推荐

  • java - Nashorn: How to select constructor to invoke - Stack Overflow

    I know from this page that I can select a method like this:API["test(Integer[])"](1);How do I

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信