2

Is it possible to disable deprecation warnings in the Scala REPL?

E.g. when I type:

scala> List(1,2,3).toSet()

I get a deprecation warning:

<console>:12: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
        signature: GenSetLike.apply(elem: A): Boolean
  given arguments: <none>
 after adaptation: GenSetLike((): Unit)
       List(1,2,3).toSet()
                        ^

Is it somehow possible to disable those warnings?

PS: I know that this is not a good idea for development, just need it for a presentation.

Florian Baierl
  • 2,378
  • 3
  • 25
  • 50
  • What `build.sbt`? I'm just using the REPL. – Florian Baierl Jan 18 '19 at 14:29
  • Yeah you are right!!! – Raman Mishra Jan 18 '19 at 14:30
  • This can help you may be https://github.com/scala/bug/issues/7934 – Raman Mishra Jan 18 '19 at 14:36
  • 1
    That was just an example. I just want to deactivate the warnings. – Florian Baierl Jan 18 '19 at 15:37
  • If you're doing a presentation, consider recording your terminal session with [asciinema](https://asciinema.org/) then editing the lines out — the recordings it generates are plain text and it's easy to delete any text you don't want displayed. – gutch Jan 18 '19 at 22:34
  • The warning in this case is that you should should have entered just `List(1,2,3).toSet` (without the empty parentheses). In _Scala_, use of empty parentheses is a convention to denote parameterless functions that have side-effects. Meanwhile, parameterless functions with no parentheses (like most conversion operations) indicates that they do not have side effects. – Mike Allen Jan 21 '19 at 00:25

1 Answers1

2

Warnings can be disabled by adding -nowarn flag. Example:

$ scala -nowarn

Then your example will print:

scala> List(1,2,3).toSet()
res0: Boolean = false

scala> 

However I don't recommend turning off those warnings (even for presentation). Please have a look at the result type of List(1,2,3).toSet(), it's Boolean not a Set[Int].

Daniel
  • 773
  • 1
  • 6
  • 13