fork download
  1.  
  2. object Main {
  3. def main(args: Array[String]) {
  4. val l = List(new AClass, AnObject, ACompanionExample)
  5. l.map(a => a.autocorrect)
  6. .foreach(println)
  7. }
  8.  
  9. }
  10.  
  11. trait Autocorrector {
  12. def autocorrect: String // this is abstract
  13. }
  14.  
  15. class AClass extends Autocorrector {
  16. def autocorrect = "AClass autocorrect"
  17. }
  18.  
  19. object AnObject extends Autocorrector {
  20. def autocorrect = "AnObject autocorrect"
  21. }
  22.  
  23. class ACompanionExample
  24. object ACompanionExample extends Autocorrector {
  25. def autocorrect = "CompanionExample autocorrect"
  26. }
  27.  
Success #stdin #stdout 0.5s 54372KB
stdin
stdout
AClass autocorrect
AnObject autocorrect
CompanionExample autocorrect