Last active
May 25, 2017 22:22
-
-
Save frgomes/8e3262a346b90b3ab3d3 to your computer and use it in GitHub Desktop.
Scala - Early initialization block after new
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() } | |
| } | |
| val acct = new { // Early definition block after new | |
| val filename = "myapp.log" | |
| } with FileLogger | |
| acct.info("hey!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment