I’m on the AboutClasses koan. So far Scala is holding up its end of the promise of terseness. For example:
This file contains 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
class ClassWithVarParameter(var description: String) | |
// Which is equivalent to the following in Java: | |
// | |
// public class ClassWithVarParameter() { | |
// | |
// private String description; | |
// | |
// public ClassWithVarParameter(String description) { | |
// this.description = description; | |
// } | |
// | |
// public String description() { | |
// return description; | |
// } | |
// | |
// public void description(String description) { | |
// this.description = description; | |
// } | |
// } |
This file contains 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
class ClassWithValParameter(val name: String) | |
// Which is equivalent to the following in Java: | |
// | |
// public class ClassWithValParameter() { | |
// | |
// private String description; | |
// | |
// public ClassWithVarParameter(String description) { | |
// this.description = description; | |
// } | |
// | |
// public String description() { | |
// return description; | |
// } | |
// } |
This file contains 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
val aClass = new ClassWithPrivateFields("name") | |
// NOTE: aClass.name is not accessible | |
// Which is equivalent to the following in Java: | |
// | |
// public class ClassWithValParameter() { | |
// | |
// private String description; | |
// | |
// public ClassWithVarParameter(String description) { | |
// this.description = description; | |
// } | |
// } |
So far, so impressed.
No comments:
Post a Comment