I must be missing something silly here. I have this:
case class Color(val rgb:Int) {
private val c = rgb - 0xff000000
val r = (c & 0xff0000) >> 16
val g = (c & 0x00ff00) >> 8
val b = (c & 0x0000ff)
}
case object Red extends Color(0xffff0000)
case object Green extends Color(0xff00ff00)
case object Blue extends Color(0xff0000ff)
Then I expect this to print true:
val c = Color(0xff00ff00)
println(c == Green)
Why doesn't it??
Case classes (or objects) inheriting from case classes is a bad practice, and is illegal as of Scala 2.9.1. Use object instead of case object to define Red, Green and Blue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With