Last active
May 25, 2017 22:22
-
-
Save frgomes/f580bae078d4c83993ef to your computer and use it in GitHub Desktop.
Scala - Early initialization block after extends
This file contains hidden or 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
| trait Logger { | |
| def log(msg: String) | |
| def info(msg: String) { log("INFO: " + msg) } | |
| def warn(msg: String) { log("WARN: " + msg) } | |
| def severe(msg: String) { log("SEVERE: " + msg) } | |
| } | |
| trait FileLogger extends Logger { | |
| val filename: String | |
| val out = new java.io.PrintWriter(filename) | |
| out.println("# " + new java.util.Date().toString) | |
| def log(msg: String) { out.println(msg); out.flush() } | |
| } | |
| class SavingsAccount extends { // Early definition block after extends | |
| val filename = "savings.log" | |
| } with FileLogger { | |
| // SavingsAccount implementation | |
| } | |
| val acct = new SavingsAccount | |
| acct.info("hey!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment