DEV Community

Parambir Singh
Parambir Singh

Posted on

2 1

scalac -feature

A useful option to turn on for the scala compiler is -feature. It emits warning and location for usages of features that should be imported explicitly.

An example such an advanced feature is implicit conversions. An implicit conversion is an implicit value of type A => B. e.g.

def main(args: Array[String]): Unit = {
    val s = "Hello, world!"
    val len: Int = s
    println(len)
}

implicit def stringToInt(s: String): Int = s.length
Enter fullscreen mode Exit fullscreen mode

Compiling this piece of code with the -feature scalac flag enabled gives the following warning:

[warn] Main.scala:8:16: implicit conversion method stringToInt should be enabled
[warn] by making the implicit value scala.language.implicitConversions visible.
[warn] ----
[warn] This can be achieved by adding the import clause 'import scala.language.implicitConversions'
[warn] or by setting the compiler option -language:implicitConversions.
[warn] See the Scaladoc for value scala.language.implicitConversions for a discussion
[warn] why the feature should be explicitly enabled.
[warn]   implicit def stringToInt(s: String): Int = s.length
[warn]                ^
[warn] one warning found
Enter fullscreen mode Exit fullscreen mode

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more