Accessing a protected static method

I am trying to use protected static method in Lucene api information lookup. My understanding of statics is that they are accessible from the definition of a class, and my understanding of the protected keyword is that they can only be accessed from instances of that class or subclass. So how exactly do you get access to a static protected method? Is my understanding wrong? I am trying to call a protected static method from a library in an imported jar. How should I do it?

In this case, I call loadStopwordSet from StopwordAnalyzerBase

+3


source to share


2 answers


Why can't you call this method by specifying it as StopwordAnalyzerBase.loadStopwordSet(params)

?

Consider this example (which compiles and works on my machine):



package p1;

public class C1 {
    protected void nonStatic() {}
    protected static void isStatic() {}
}

----
package p2;

import p1.C1;

public class C2 extends C1 {
   public void someMethod() {
     super.nonStatic();
     C1.isStatic();     // or even C2.isStatic()
   }
}

      

Going back to the original question, I see that this method is being called from ArabicAnalyzer: 78 (Lucene version 4.9.0, package org.apache.lucene.analysis.ar

) as well as many others.

+2


source


The "base" part of the class name should give you a hint: this is called a call from a subclass of StopwordAnalyzerBase. It is static because it does not have to be an instance method (it is self-contained and does not change the state of its caller). Looking at the API, I won't say why it would be protected, although disregarding the principle of least privilege, I suppose



+2


source







All Articles