Scala implicit conversions is a powerful tool for Scala coding. It lets you decrease redundancy in your code and lets you make the code easier to read.
Scala implicit conversions feature enables you to do the following:
- Highlight methods in which implicit converions were used.
- Select from the available list of all applicable implicit conversions.
- Apply conversion either explicitly or in shorter version and still get the same result.
- Invoke implicit parameters.
If Scala type-aware highlighting is enabled then IntelliJ IDEA highlights methods that are added via implicit conversions with a grey underline:
Select an expression and press Ctrl+ Shift+ Q (Ctrl+Qfor Mac) to invoke the list of applicable implicit conversions. The list shows the regular scope displayed on the top and the expanded scope that is displayed on the bottom of the list.
|Note: IntelliJ IDEA highlights an implicit converion that was used for the selected expression. If IntelliJ IDEA cannot find the implicit conversion or if it finds more than one match then the list Introduce Variable opens.|
You can make the implicit conversion method explicit. Press Alt+ Enterand select Make explicit or Make explicit (Import method) :
If you select Make explicit then IntelliJ IDEA returns a method call with the class name. It might be helpful if you need to make sure that the compiler imports the particular implicit conversion method that you originally wanted:
If you select Make explicit (Import method) then the method is imported statically and IntelliJ IDEA returns just its call without the class name. Also, the next time you open the list of useful implicit conversions you will see this method in the regular scope:
Place a cursor to the method where implict conversion was used and press Ctrl+ Shift+ P(Meta+ Shift+ Pfor Mac) to invoke implicit parameters. It might be helpful for code analizing when you want to find out what implicit parametrers were passed to the particular call.
|Note: IntelliJ IDEA hightlights the method call where implicit parameters were used.|
If IntelliJ IDEA cannot find method calls where implicit paramerers were passed, it displays a pop-up message:
|See also the tutorial Getting started with Scala in IntelliJ IDEA.|