Ask Your Question
4

Does Scala lack the transitive property of covariance?

asked 2023-07-01 23:36:41 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-07-01 23:46:02 +0000

lakamha gravatar image

No, Scala does not lack the transitive property of covariance. The transitive property of covariance states that if C is a subtype of B, and B is a subtype of A, then C is a subtype of A. This property is present in Scala's type system. For example:

class Animal
class Mamal extends Animal
class Dog extends Mamal

val mamal: Mamal = new Dog
val animal: Animal = mamal

In this example, Dog is a subtype of Mamal, and Mamal is a subtype of Animal. Therefore, Dog is also a subtype of Animal, and the third line of code is valid. This demonstrates the transitive property of covariance in Scala.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-01 23:36:41 +0000

Seen: 16 times

Last updated: Jul 01 '23