Will groovy (grails) give you compile time checking like java?

后端 未结 5 960
感动是毒 2021-02-20 18:20

Will groovy (grails) give you compile time checking like java?

If you always specify the type, will that change things much?

  • 2021-02-20 18:31

    Groovy 2.0 has @CompileStatic and @TypeChecked you can check this good performance test between Groovy 2.0 and Java http://java.dzone.com/articles/groovy-20-performance-compared

    As topr said... this feature will be avaliable in grails until version 2.2

    0 讨论(0)
  • 2021-02-20 18:33

    Things are changing... http://portal.sliderocket.com/vmware/Groovy-2-0-Static-Type-Checking-and-Compilation

    0 讨论(0)
  • 2021-02-20 18:40


    It was designed to be a dynamic-typing programming languages which is pretty much the opposite as compile time checking.

    You'll have to add more unit tests instead.

    0 讨论(0)
  • 2021-02-20 18:41

    The Groovy compiler will of course find syntax errors, but almost no type errors as with Java. Even the use of undeclared variables will often pass compilation.

    Declaring types will increase the amount of checking that is done, but not by much.

    This is because Groovy is a dynamic language with powerful metaprogramming features that make it impossible for the compiler to know e.g. what methods or fields a given object will have at compile time, since it's possible for this to be changed at runtime by other code.

    However, IDE plugins offer a compromise by marking members of variables with a declared type that are not present in the class declaration as possible errors. Then the developer can decide whether this member will be present at runtime, or whether he just made a typo. Additionally, known class members appear in autocompletion.

    0 讨论(0)
  • 2021-02-20 18:51

    Since Groovy 2.0 it is possible to check types at compile time. Annotations can be used on class or method: @TypeChecked or @CompileStatic. The 1st one tells compiler to do type checking during compilation and the 2nd one force it to do 'static compilation' which more or less results with binary code like from native JAVA compiler. Of course, usage of the 2nd annotation involves type checking by itself.

    Grails 2.2 is the first release that uses Groovy 2.0.

    0 讨论(0)