class A {
private def sayHello() {
println \"Anish\"
}
}
def a_obj = new A()
a_obj.sayHello()
output : Anish
You can use closures to achieve a similar effect, basically the same way you would do information hiding with Javascript.
package test
class FunctionTests {
def privilagedObj = {
def privVar = 'foo'
def privateFunc = { x -> println "${privVar} ${x}"}
return {x -> privateFunc(x) }
}
public static void main(String[] args) {
def test = new FunctionTests().privilagedObj()
test('bar')
}
}