Improper handling of Java Class object when in native Object mode

21 views
Skip to first unread message

Udo

unread,
May 24, 2012, 7:46:20 AM5/24/12
to java2...@googlegroups.com
When running in native Object mode (as described here) the Java "Class" object becomes a "native" object. 

This leads to problems e.g. when the Java Class object is used as a key in a HashMap, because the method hashCode() is not defined.

E.g. running this code in native Object mode:

    HashMap classNames = new HashMap();

    String fooCmt = "The Foo Class";

    classNames.put(Foo.class, fooCmt);


will throw an exception:

    TypeError: 'undefined' is not a function (evaluating 'key.hashCode()')


As Java "Class" objects are "Java Objects" I would have expected also the "Class" class inherits from the JavaObject class/prototype. But this is not the case when in "native Object" mode.


You can see the issue live at: http://www.abego.org/j2s/J2STest/index.html


Udo




Zhou Renjian

unread,
May 25, 2012, 12:17:06 PM5/25/12
to java2...@googlegroups.com
In fact, lots of methods in Java class object are missed in Java2Script environment. It is considered a defect of J2S and won't be fixed totally for performance reason.

In case you report this problem, I think there are cases using *.class#hashCode. so I just added this method for both normal and j2s.objective.native modes.


For compiled and packed version of this bug-fix, you can download and unzip
into plugins/net.sf.j2s.lib_2.0.0/j2slib/ , overwrite existed *.js files.

Thanks for reporting bugs.

Regards,
Zhou Renjian





Udo




--
You received this message because you are subscribed to the Google Groups "Java2Script" group.
To view this discussion on the web visit https://groups.google.com/d/msg/java2script/-/XiYH8lyutekJ.
To post to this group, send email to java2...@googlegroups.com.
To unsubscribe from this group, send email to java2script...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/java2script?hl=en.

Udo

unread,
May 30, 2012, 8:50:31 AM5/30/12
to java2...@googlegroups.com
Hi Renjian,

many thanks. That fixes the issue.

Udo

Regards,
Zhou Renjian



To unsubscribe from this group, send email to java2script+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages