Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.