Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
pp:2024:scala:l05 [2024/03/31 16:40] tudor.condrea |
pp:2024:scala:l05 [2024/03/31 16:45] (current) tudor.condrea |
||
---|---|---|---|
Line 27: | Line 27: | ||
==== Contravariance ==== | ==== Contravariance ==== | ||
- | We introduce a veterinarian class. Consider why this class is contravariant in ''T''. | + | We introduce a veterinarian class. Consider why this class should be contravariant in ''T''. |
<code scala> | <code scala> | ||
- | class Vet[-T <: Animal] { | + | class Vet[T <: Animal] { |
def treat(patient: T): String = { | def treat(patient: T): String = { | ||
- | s"Can treat $patient" | + | "Can treat " + patient.toString |
} | } | ||
} | } |