What is j2cl?

3,268 views
Skip to first unread message

Marko

unread,
Oct 23, 2015, 6:14:17 PM10/23/15
to GWT Users
I see the term "j2cl" comming up in several threads connected with GWT 3.0. What does it mean?

I speculate that this is a "Java-to-Closure-Library" transpiler, which would be GREAT, because you wouldn't depend on JRE emulation library anymore and GWT 3.0 would be safe from "Oracle copyright lawsuit nonsense". Additionally you could integrate JavaScript Closure Library code with Java code transpiled to Closure Library and it would use the exactly same class library... I guess also that Google would profit from such a transpiler in Google Inbox and other similar projects...

I hope I am not speculating too much into the Google's trade secrets and that this post will not be deleted because of this... :-)

Marko

Thomas Broyer

unread,
Oct 23, 2015, 6:31:40 PM10/23/15
to GWT Users
You're almost right (Googlers will correct me if I'm wrong).

j2cl stands for Java-to-CLosure. It's not much about the Closure Library but rather the Closure Compiler. It's a transpiler from Java to Closure-annotated ES6 (there are a couple videos about this from the GWT Meetup earlier this year: https://www.youtube.com/playlist?list=PL1yReUCGwGvrqscLu1EAyYRPrr0ceEHLE ), type annotations will help the Closure Compiler prune unused code to further optimize the produced JS.

But it won't free us from the JRE emulation library.

Marko

unread,
Oct 24, 2015, 12:48:06 PM10/24/15
to GWT Users
Thank you Thomas for this answer! This is great!

Replacing JRE emulation with Closure Library (java.util.HashMap => goog.structs.Map, java.util.Set => goog.structs.Set, etc.) would eliminate the need for JRE emulation and protect us in case Oracle wins in court. I guess that in this case Closure Library will need to be extended with some methods and classes in order to provide functionality which is present today in JRE emulation library. But this can also be done later (j2cl v2.0).

Marko

James Nelson

unread,
Nov 18, 2015, 4:01:42 PM11/18/15
to GWT Users
Marko, even is the closure libs were extended to look like java Map/Set, that does not replace the need to emulate Map/Set.

Gwt already has its own versions of HashMap and ilk, and even if they could compile them directly to closure types,
we would STILL need to use the java.util.* apis, because the whole point of a java transpiler is that you can use all the core types across all your environments.

Consider the typical cross platform project... web, android, ios (via j2objc, etc).
If you want to share code between them, you use types they all have (Map, Set, List, etc).
If you have platform specific code, you can use a js map or whatever you have.

Marko

unread,
Nov 23, 2015, 5:51:43 AM11/23/15
to GWT Users
Hi James!

The idea would be to use Java Maps/Sets/Lists/etc in your platform independent code - for web, android, ios. But j2cl would translate this platform independent code into JavaScript based on Closure Library so that in runtime JavaScript code would use goog.structs.Map instead of java.util.HashMap and goog.structs.Set instead of java.util.Set...

Marko

James Nelson

unread,
Nov 27, 2015, 5:34:51 PM11/27/15
to GWT Users
Ok.

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.

Norbert Sándor

unread,
Feb 23, 2016, 5:47:58 AM2/23/16
to GWT Users
> 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).

This is what http://www.jsweet.org/ does...

Thomas Broyer

unread,
Feb 23, 2016, 6:08:48 AM2/23/16
to GWT Users


On Tuesday, February 23, 2016 at 11:47:58 AM UTC+1, Norbert Sándor wrote:
> 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).

This is what http://www.jsweet.org/ does...

AFAICT from their docs, most of the Java "standard library" is unavailable to JSweet: java.lang.* "wrappers" around primitive types don't allow any method call (in other words, they're just nullable primitives), no java.util.Date, no java.util.List et al.
No java.util.Map.

Hristo Stoyanov

unread,
Feb 23, 2016, 4:49:57 PM2/23/16
to GWT Users
... they did it on purpose:

... a consequence of the simpler approach JSweet takes,  is that they actually shipped and will be able to evolve jsweet much more quickly in future, IMO

Vassilis Virvilis

unread,
Feb 23, 2016, 5:15:41 PM2/23/16
to google-we...@googlegroups.com
Looks like GWT follows suit with the jsinterop development.

Still it is good to have things such Collection<MyDataType> and Map<> for compatibility with backend classes. jsweet looks like it provides the same deal for javascript (instead of java) with its nodejs compatibility. However my backend (several KLOC) is java and GWT is a better proposition for me.


--
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 google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis

Norbert Sándor

unread,
Jul 18, 2016, 10:20:29 AM7/18/16
to GWT Users
Is J2CL available to the public yet?
This thread is very old and I've seen no news about it...

Thanks,
Norbi
Reply all
Reply to author
Forward
0 new messages