title: How to make a Groovy method truly protected
body: <p>Trying to make a method in groovy <code>protected</code>:</p>
  
  <pre><code>package com.foo
  
  class Foo {
  
    protected def getSomething(){
    }
  }
  </code></pre>
  
  <p>This doesn't work since groovy by default makes pretty much everything visible, so I tried using <code>@PackageScope</code></p>
  
  <pre><code>package com.foo
  
  import groovy.transform.PackageScope    
  
  @PacakgeScope
  class Foo {
  
    def getSomething(){
    }
  }
  </code></pre>
  
  <p>This sort of works, but only if the caller uses <code>@CompileStatic</code>...</p>
  
  <pre><code>   package com.bar
  
     class Bar {
  
     @CompileStatic
     static void main(args){
        def f = new Foo()
        println f.getSomething() 
     }
  </code></pre>
  
  <p>The above throws <code>IllegalAccessError</code>, that's nice, but without <code>@CompileStatic</code>, no error is generated; not so nice. I can't force users to compile statically, so is there any alternative to enforce <code>protected</code> methods?</p>
  
  <h2>From Groovy <a href="http://groovy.codehaus.org/Differences+from+Java" rel="noreferrer">Documentation</a></h2>
  
  <blockquote>
    <p>Protected in Groovy has the same meaning as protected in Java, i.e.
    you can have friends in the same package and derived classes can also
    see protected members.</p>
  </blockquote>
  
  <p>Ok, if <code>protected</code> has the same meaning in Groovy but isn't enforced as such, doesn't that erode its meaning? Maybe I'm missing something, </p>