Relative Content

Tag Archive for trait

Why are Scala’s Either and Option types not interfaces/traits but classes?

I wanted to create a class CompileResult, that can be treated like an Either type but has some additional useful methods. It should be a CompileSuccess or a CompileFailure (which, too, has some extended functionality). However I can’t do that because Either is an abstract class and I don’t want to extend it but rather use delegation and have an Either stored internally.

Why can’t the Scala compiler give pattern matching warning for nonsealed classes/traits?

If I use an unsealed trait or abstract class in Scala and then use pattern matching, I wonder, does the compiler not know at compile time for this particular patternmatch what possible implementations of this trait/class are available? So, if it does, could it not give pattern match warnings even though that the trait/abstract class is not sealed because he knows which types could be used, by checking all the possible dependencies/imports?