Bug report: can't call static methods on a Java class instance
tibetty
xihua.duan at gmail.com
Wed Oct 30 13:32:33 UTC 2019
It works and many thanks for your timely response, Joao! However,
personally I think it's problematic for Nashorn not to support the static
method invocation from an extended class. Any design consideration under
the hood?
On Wed, Oct 30, 2019 at 8:27 PM João Paulo Varandas <joaovarandas at inpaas.com>
wrote:
> Call parseObject directly from the class that contains the static method,
> not from the extended one.
>
> var jso = Java.type('com.alibaba.fastjson.JSON').parseObject(json);
>
>
>
> https://github.com/alibaba/fastjson/blob/master/src/main/java/com/alibaba/fastjson/JSON.java
>
>
>
>
>
> On Wed, Oct 30, 2019 at 9:22 AM tibetty <xihua.duan at gmail.com> wrote:
>
>> I used your method, but it stills failed calling a static method of a 3rd
>> party class (com.alibaba.fastjson.JSONObject):
>> Nashorn (JS) code:
>> var jso = Java.type('com.alibaba.fastjson.JSONObject').parseObject(json);
>>
>> Error Message:
>> Exception in thread "main" javax.script.ScriptException: TypeError:
>> Java.type("com.alibaba.fastjson.JSONObject").parseObject is not a function
>> in <eval> at line number 1
>>
>> How to overcome this kind of problem?
>>
>>
>>
>>
>> --
>> Sent from: http://nashorn.36665.n7.nabble.com/
>>
>
> " This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they are
> addressed. If you have received this email in error please notify the
> system manager. This message contains confidential information and is
> intended only for the individual named. If you are not the named addressee
> you should not disseminate, distribute or copy this e-mail. Please notify
> the sender immediately by e-mail if you have received this e-mail by
> mistake and delete this e-mail from your system. If you are not the
> intended recipient you are notified that disclosing, copying, distributing
> or taking any action in reliance on the contents of this information is
> strictly prohibited. "
>
More information about the nashorn-dev
mailing list