IntelliJ IDEA 2016.3 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/2016.3/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/2016.3/grey_underline.png

Invoking Implicit Conversion Methods

  • Select an expression and press Shift+Ctrl+Q (Ctrl+Q for OS X) 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/2016.3/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/2016.3/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/2016.3/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/2016.3/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/2016.3/implicit_param.png
  • If IntelliJ IDEA cannot find method calls where implicit parameters were passed, it displays a pop-up message:
    /help/img/idea/2016.3/no_implicit_param.png
Last modified: 29 November 2016