Skip to content

Instantly share code, notes, and snippets.

@ssanj
Created December 12, 2019 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssanj/53ae650d4bf46a07059ba0d4fa4c5dfc to your computer and use it in GitHub Desktop.
Save ssanj/53ae650d4bf46a07059ba0d4fa4c5dfc to your computer and use it in GitHub Desktop.
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