IntelliJ IDEA 2017.1 Help

Working with Scala Implicit Conversions

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.

Implicit Conversion Highlighting

If Scala type-aware highlighting /help/img/idea/2017.1/type_aware_highlighting_icon.png is enabled then IntelliJ IDEA highlights methods that are added via implicit conversions with a grey underline:

/help/img/idea/2017.1/grey_underline.png

Invoking Implicit Conversion Methods

  • Select an expression and press Shift+Ctrl+Q (Ctrl+Q for macOS) 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.
    /help/img/idea/2017.1/choose_implicit_conv.png
  • You can make the implicit conversion method explicit. Press Alt+Enter and select Make explicit or Make explicit (Import method):
    /help/img/idea/2017.1/choose_implicit_with_make_exp.png
  • 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:
    /help/img/idea/2017.1/make_explicit.png
  • 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:
    /help/img/idea/2017.1/make_explicit_import_met.png

Invoking Implicit Parameters

  • Place a cursor to the method where implicit conversion was used and press Ctrl+Shift+P to invoke implicit parameters. It might be helpful for code analyzing when you want to find out what implicit parameters were passed to the particular call. IntelliJ IDEA also lets you view the recursive implicit parameters.
    /help/img/idea/2017.1/implicit_param.png
  • If IntelliJ IDEA cannot find method calls where implicit parameters were passed, it displays a pop-up message:
    /help/img/idea/2017.1/no_implicit_param.png
Last modified: 18 July 2017