Closed wunderabt closed 3 years ago
A Scala apply
method doesn't have to return a specific type. You can have it return an object of any type.
Yep, I guess I was primed by Chapter 3.5 that this was meant to be a companion object to the Mac
class. But maybe that wasn't the intention here. Reading it again, it doesn't say to implement it as a companion object. So I guess I just made the connection to companion objects even when it wasn't asked for here. (or I'm still lacking in understanding of the way companion objects work)
My understanding of scala companion objects is that they provide a factory method
apply
that returns an instance of the class. However the solution in Chapter 3.6 merely saysa * b + c
which is not an instance of classMac
. Instead it's code duplication of theMac
constructor.I would have expected something like
However, I don't know how to derive the
genOut
type. What am I missing?