Is there a Coffeescript for Java? In other words X

2019-03-18 03:43发布

问题:

Is there a language that gets compiled to Java code (not Byte code but Java .. so no Groovy, Scala, Jython, JRuby etc.)?

In other words is there a CoffeeScript for Java?

One of the major flaws I have against Java is that its so damn verbose and that it doesn't have multiple inheritance. It seems reasonably that one could just clean up the syntax add mixins/traits and closures through code generation.

Yeah its not elegant but coffeescript does it.

回答1:

Yep, Xtend. It's a new language brought to you by the Eclipse folks: http://www.eclipse.org/xtend/

No multiple inheritance (that would be a fundamental change to Java semantics), but lots of syntactic sugar, just like CoffeeScript.

Also take a look at Mirah: http://www.mirah.org/



回答2:

If you think about it, CoffeeScript compiling to Javascript means you can use coffeescript itself as a Java language. With the latest CoffeeScript (1.1.3) you might need to use Rhino directly because it triggers a JS implementation bug in the current jdk, but outside of that, you should be good to use the compiled js files to interact with Java code. :)



回答3:

I wrote a pre-processor for text files that introduces {s and }s where there was indentation. I called it:

  • Significant-White-Space (SWS)

It is nowhere near stable, and it doesn't address some of the other shortcuts you point out that Coffeescript offers, but it does work as a proof-of-concept.



回答4:

I wrote a transcompiler (just like CoffeeScript) to Java that supports multiple inheritance. It is very buggy and limited and does not allow many flexible formatting options, but it is still there and I would be more than happy if you checked it out or made a branch from it to improve it. I will probably add more features and fix many of the bugs, but for now, it at least works.

https://github.com/Philoprogrammer/Java-With-Multiple-Inheritance