Guest User

Untitled

a guest
Feb 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. trait WhoAreYou {
  2. def whatClassAmI: Class[_] = this.getClass
  3. println("I've been mixed into " + whatClassAmI)
  4.  
  5. if (whatClassAmI == classOf[Bar]) {
  6. println("Holy cow batman, I'm part of a Bar")
  7. }
  8. }
  9.  
  10. class Foo extends WhoAreYou
  11. class Bar extends WhoAreYou
  12.  
  13. object MyApp {
  14. val f = new Foo
  15. val b = new Bar
  16.  
  17. def main(args: Array[String]) {
  18. println("foo " + f.whatClassAmI)
  19. println("bar " + b.whatClassAmI)
  20. }
  21. }
Add Comment
Please, Sign In to add comment