I’m looking at p. 469 of “Programming in Scala” Second Edition. There is a line of code that reads:
type Currency <: AbstractCurrency
I cannot decipher what this means.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It means an abstract type member is defined (inside some context, e.g. a trait or class), so that concrete implementations of that context must define that type. However, there is a constraint that this type (
Currency) must actually be a subtype ofAbstractCurrency. That way the abstract context can operate withCurrency, knowing that it understands every operation ofAbstractCurrency.Trying to define
Currencywithout constraints:Fails. With constraints ok: