Valid Java code that is NOT valid Groovy code?

后端 未结 8 1988
忘了有多久
忘了有多久 2020-12-05 04:50

Most Java code is also syntactically valid Groovy code. However, there are a few exceptions which leads me to my question:

Which constructs/features in Java are syn

相关标签:
8条回答
  • 2020-12-05 05:41

    Non-static initialization blocks:

    class Foo {
      Integer x;   
      { x = 1; }
    }
    

    UPDATE: This is in fact valid Groovy code.

    0 讨论(0)
  • 2020-12-05 05:45

    Declaring an array of a given type using [] after the variable name instead of the type works in Java but not Groovy.

    byte[] buff = new byte[1024]; // Works

    byte buff[] = new byte[1024]; // Not Groovy

    Results in Primitive type literal: byte cannot be used as a method name

    0 讨论(0)
提交回复
热议问题