Friday, November 27, 2015

Re: What is j2cl?


So, I have Map<MyCustomObject, Stuff>, how do I map that to goog.structs.Map?

The closure objects do not behave 100% the same as the java objects, and if you expect your code to do the same thing on every platform (very common, reasonable expectation), then you can't pick an emulation library that is functionally different.

For maps with string keys maybe then you could use closure Map, but the emulated java Maps all have optimizations for String that just make them behave like a javascript dictionary.
Or things like Iterators; how are you going to map a java iterator such that it will just work, without having to change any code?  Emulation, maybe?

Sooo, I still don't see any path to actually removing the emulation code.

Unless you can get a perfect 1:1 mapping to java apis, people are going to use a java type, and not get java behavior.  That would be Very Bad (tm).

There are plenty of options for making your own Map or Set type that itself maps to closure and can have slightly different behavior,
and it would be on you to proactively choose this map/list/set type yourself.

I actually don't use java.util collections and prefer my own abstraction which can supply an optimized api for whatever platform you are on (I specialize in cross platform; I maintain a library called xapi);
even though I also maintain a fork of Gwt where I could just mod the java.util classes to "work better for javascript", I would not do such a thing, because whenever I ask for an ArrayList or a LinkedHashSet, I want exactly the behavior those classes claim to expose.

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment