Groovy 3语法是否与Java语法完全兼容?

huangapple go评论82阅读模式
英文:

Is Groovy 3 syntax an exact superset of Java syntax?

问题

这个问题,Groovy语法是否完全是Java语法的超集?,在近十年内没有更新。

我的理解是,Groovy 3已经填补了与Java语法之间的剩余差距,成为了一个纯粹的超集。我相信这就是Wikipedia在提到Groovy时所指的,

与Java语法兼容

这是正确的吗,还是仍然有Java(11)语法在Groovy中无效?

英文:

The question, Is Groovy syntax an exact superset of Java syntax? has not been updated in nearly a decade.

My understanding is that Groovy 3 has closed the remaining gaps with Java syntax, to become a pure superset. I believe this is what Wikipedia means when it refers to Groovy as,
> Java-syntax-compatible

Is this correct, or is there still Java (11) syntax that is invalid Groovy?

答案1

得分: 1

我找到了一个权威页面:http://groovy-lang.org/differences.html,然而,大多数的区别是行为上的(运行时),而不是语法上的。

可能只有两个语法差距仍然存在。

  1. Groovy 3 不支持 Java 的速记数组初始化。int[] array = {1, 2, 3};
  2. Groovy 3 不支持 Java 的字符串字面字符 $String dollar = "$"

Groovy 3 包括五个额外的关键字;然而,这可能对编译 Java 代码没有问题。

Groovy 比 Java 更宽松,因为它允许一些关键字出现在在 Java 中是非法的地方。

英文:

I found an authoritative page: http://groovy-lang.org/differences.html, however, most of the differences are behavioral (runtime) rather than syntactic.

There may be only two syntax gaps remaining.

  1. Groovy 3 does not support Java's shorthand array initialization.<br/>
    int[] array = {1, 2, 3};
  2. Groovy 3 does not support Java's String literal dollar character.<br/>
    String dollar = &quot;$&quot;

Groovy 3 includes five additional keywords; however, this may not be a problem for compiling Java code.
> Groovy is less stringent than Java in that it allows some keywords to appear in places that would be illegal in Java

huangapple
  • 本文由 发表于 2020年8月9日 01:33:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/63318374.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定