Private method in groovy is not private

后端 未结 5 2094
慢半拍i
慢半拍i 2020-12-18 19:12
class A {
    private def sayHello() {
       println \"Anish\"
    } 
 }

 def a_obj = new A()
 a_obj.sayHello()

output : Anish

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 19:43

    As other posts have mentioned, this may be a bug in Groovy. I've been sticking to a simple convention of prefixing private member names with a leading underscore (similar to Python) to denote that it's private which helps me understand from a client side perspective what I should be calling.

提交回复
热议问题