![]() If our method would have a Map argument already we can re-use it. Here we can choose to create a new Map parameter for named arguments. We select the option Convert parameter to map entry: Now we activate the Groovy intentions (for me it is Alt+Enter or try Shift+Shift and type Show intentions actions) while we place the cursor on the parameter greeting. Suppose we have the following source code with a simple method definition, 2 arguments, and the invocation of the method: IntelliJ IDEA has a Groovy intention to turn method parameters into a Map parameter for named arguments with a few mouse clicks. This leads to better readable code and that is very useful. Inside our method or constructor we can then access the Map argument and get the values for the keys. This means all key/value arguments are gathered together and assigned to the Map argument. If the argument is the first in the list of arguments then Groovy allows use to use named arguments when we invoke the method or constructor. Instead of a list of arguments for a method or constructor we can use a Map argument. A very useful feature in Groovy is the use of named arguments.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |