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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.