Created
December 12, 2019 12:00
-
-
Save ssanj/53ae650d4bf46a07059ba0d4fa4c5dfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> trait A { val a: String = "this is A" } | |
defined trait A | |
scala> trait B { val b: String = "this is B" } | |
defined trait B | |
scala> trait C { val c: String = "this is C" } | |
defined trait C | |
scala> val abc = new A with B with C | |
abc: A with B with C = $anon$1@786ff1cb | |
scala> abc.a | |
res0: String = this is A | |
scala> abc.b | |
res1: String = this is B | |
scala> abc.c | |
res2: String = this is C | |
scala> def onlyAB(ab: A with B): A with B = ab | |
onlyAB: (ab: A with B)A with B | |
scala> val ab = onlyAB(abc) | |
ab: A with B = $anon$1@786ff1cb | |
scala> ab.c | |
^ | |
error: value c is not a member of A with B | |
scala> ab.a | |
res5: String = this is A | |
scala> ab.b | |
res6: String = this is B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment