What does 'private' mean in Groovy?

11,477

By design Groovy should respect the private modifier, however the current implementation takes no account of it.

There are further details in groovy call private method in Java super class

Share:
11,477

Related videos on Youtube

ripper234
Author by

ripper234

See blog or LinkedIn Profile

Updated on February 08, 2020

Comments

  • ripper234
    ripper234 about 4 years

    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")
    println u.name
    
    • tim_yates
      tim_yates over 13 years
    • ripper234
      ripper234 over 13 years
      @James - try it, it compiles without errors.
    • dnim
      dnim over 10 years
      Groovy generates gettes/setters for private fields and if you try hit the private field like u.name Groovy invokes u.getName(){this.name} generated or declared method for it. So this behavior looks fine for me. Anyway Groovy has a lot of the issues with privacy ;)