What does 'private' mean in Groovy?

后端 未结 2 1035
长情又很酷
长情又很酷 2020-12-15 17:45

The following code sets a private method. So how private really is private?

public class Person {
 private String name
}

def u = new Person(name:\"Ron\")
pr         


        
2条回答
  •  渐次进展
    2020-12-15 18:30

    I think we can access this because groovy adds getters and setters for all the variables. These methods are public, and hence private variables can be accessed outside the scope, that you would expect them be.

    As in case of private methods, well you can get around anywhere with the concept of MetaClass.

提交回复
热议问题