This is a major release. JSweet now supports much better the Java language without loosing its original spirit of low-impedance between Java and JavaScript.
Here is a summary of the new features:
java.lang.String
and java.lang.Math
APIs are directly mapped to JavaScript at compile-time. As a result, you can use Java core API but, under the hood, it is still JavaScript that it used (not an emulation on contrary to most approaches).java.util
and java.io
), JSweet rely on the J4TS project, which is a fork of GWT’s JRE emulation. J4TS removes the Java emulation part from GWT and compiles it with JSweet to generate the j4ts candy, which can be used like any other JavaScript library (except that it provides an implementation of some Java APIs).instanceof
operator for interfaces, and it mimics the JLS for static initializers.Here is an example of a valid JSweet program that mixes Java and JavaScript APIs in a very straightforward way (see the “Complementary colors” program in the live sandbox):
public class ComplementaryColors { private static Map<String, String> complementaryColors = new HashMap<String, String>(); static { complementaryColors.put("green", "magenta"); complementaryColors.put("red", "cyan"); complementaryColors.put("blue", "yellow"); } public static void main(String[] args) { console.info("starting Java API example"); HTMLUListElement ul = document.createElement(StringTypes.ul); document.body.appendChild(ul); for (Map.Entry<String, String> e : complementaryColors.entrySet()) { HTMLLIElement li = document.createElement(StringTypes.li); ul.appendChild(li); HTMLAnchorElement a = document.createElement(StringTypes.a); a.innerHTML = "Complementary color for " + e.getKey(); a.addEventListener(StringTypes.click, evt -> { alert("The complementary color for " + e.getKey() + " is " + e.getValue()); return evt; }); a.href = "#"; li.appendChild(a); System.out.println(e.getKey() + " -> " + e.getValue()); } } }
To get a complete list of changes, go to the Gihub release page.
To checkout the Java APIs that are now supported by JSweet, go to the Language Specification (download PDF), and checkout the J4TS project.
If you like it and want to help us, a star on Github would be a good start 😉