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

后端 未结 5 1490
借酒劲吻你
借酒劲吻你 2021-02-20 18:12

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

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

5条回答
  •  被撕碎了的回忆
    2021-02-20 18:37

    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.

提交回复
热议问题