Jabda
Jabda

Reputation: 1792

final static object in Groovy

Is there a difference? What is the preferred or correct usage in groovy. If my variable is final and static should I be using def ?

final static def MY_STRING

or

final static String MY_STRING

Upvotes: 2

Views: 341

Answers (1)

ataylor
ataylor

Reputation: 66099

There's no one variation that's better in all circumstances. By specifying the type with String, you can get compile-time type checking by using the @TypeChecked or @CompileStatic annotations. If you don't specify a type, you can leave off def entirely, for slightly more concise code:

final static MY_STRING

Choose the one that matches your own priorities and coding style.

Upvotes: 6

Related Questions