let's say I have a common feature of the command with the execute method, which accepts input and returns Output. Something like
trait Input; trait Output; trait Command[I <: Input, O <: Output] { def execute(input: I): O; }
Then I'm going to create various teams, something like
class SampleInput extends Input class SampleOutput extends Output class SampleCommand extends Command[SampleInput, SampleOutput] { def execute(input:SampleInput):SampleOutput = new SampleOutput() }
The problem with this is that I can create a command with SampleAInput and SampleBOutput , and the compiler will accept this happily. How to enforce this so that the compiler crashes with a type mismatch error?
Somehow I need to group Input and Output under a type and pass this type to create a command. How to do it?
types scala
sanjib
source share