Created
February 21, 2015 15:16
-
-
Save shigemk2/08e6bfdc566cee548c52 to your computer and use it in GitHub Desktop.
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
// varはおーけー | |
class Person1(var name: String) | |
val p1 = new Person1("Alvin Alexander") | |
// getter | |
println(p1.name) | |
// setter | |
p1.name = "Fred Flintstone" | |
println(p1.name) | |
// valをつけるとsetterが直接使えなくなる | |
class Person2(val name: String) | |
val p2 = new Person2("Alvin Alexander") | |
println(p2.name) | |
// p2.name = "Fred Flintstone" // error | |
// privateをつけるとgetterやsetterが直接使えなくなる | |
class Person3(private var name: String) { def getName {println(name)} } | |
val p3 = new Person3("Alvin Alexander") | |
// p.name // error | |
p3.getName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment