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

后端 未结 5 1690
感动是毒
感动是毒 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?

5条回答
  •  青春惊慌失措
    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.

提交回复
热议问题