Skip to content

Instantly share code, notes, and snippets.

@deserat
Last active December 20, 2015 05:08
Show Gist options
  • Save deserat/6075439 to your computer and use it in GitHub Desktop.
Save deserat/6075439 to your computer and use it in GitHub Desktop.
Traits can be implemented and extended on the fly with initialized values. This includes JAVA Interfaces.....
trait Similarity {
def isSimilar(x: Any): Boolean
def isNotSimilar(x: Any): Boolean = !isSimilar(x)
}
val b = 25
val foo = new Similarity() {
var x: Int = b
def isSimilar(x: Any): Boolean = {
true
}
}
foo.x
// 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment