Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to know what Scala implicit is being used, without the help of an IDE?

Tags:

scala

implicit

For the times when you are reading source code without an IDE at hand.

like image 330
Luciano Avatar asked Apr 26 '13 21:04

Luciano


People also ask

What is the use of implicit in Scala?

The implicit system in Scala allows the compiler to adjust code using a well-defined lookup mechanism. A programmer in Scala can leave out information that the compiler will attempt to infer at compile time. The Scala compiler can infer one of two situations: A method call or constructor with a missing parameter.

What is implicit parameter in Scala?

Implicit parameters are the parameters that are passed to a function with implicit keyword in Scala, which means the values will be taken from the context in which they are called.

Where does Scala look for Implicits?

Unless the call site explicitly provides arguments for those parameters, Scala will look for implicitly available given (or implicit in Scala 2) values of the correct type. If it can find appropriate values, it automatically passes them.


1 Answers

Compile with the Xprint:typer scalac option.

This tells scalac to explain what it's doing.

This article explains the option and gives an example of the output (towards the bottom).

like image 114
Boris the Spider Avatar answered Oct 04 '22 22:10

Boris the Spider