Variables are used public in classes using the default visibility modifier. A setter and a getter is created for every member variable, but in Kotlin you do for example:
class Person {
var name: String = "unknown"
}
fun main(args: Array<String>) {
val person = Person()
person.name = "kevvex"
println("${person.name}")
}
Is this still not breaking the rule of encapsulation due to the getter and setter being applied when using:
person.name = "kevvex"
If so, how can that be encapsulation? The variable is still public. Declaring it as private would force me to create a setter and getter to get the variable, because of the private visibility modifier.
I'm comparing to Java that often has member variables as private and a public setter and getter for every member variable.