Last active
August 29, 2015 13:58
-
-
Save alissapajer/9938451 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.ConcurrentHashMap | |
object Why { | |
val data = new ConcurrentHashMap[Int, String] | |
def update(int: Int, str: String): Unit = { | |
data.put(int, str) | |
} | |
} | |
// This compiles! But the return type of ConcurrentHashMap#put for our hash map `data` should be String | |
// Why does Scala let the `update` function return Unit? |
So it turns out you can solve this problem with an implicit def converting Unit
to your own special MyUnit
and then using MyUnit
everywhere you'd otherwise use Unit
WartRemover also catches value discarding - pretty much the first thing I put in 🐱
I strongly recommend using -Xfatal-warnings -Ywarn-value-discard
!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found it: -Ywarn-value-discard