All Downloads are FREE. Search and download functionalities are using the official Maven repository.

resources.report.rules.pmd.AccessorMethodGeneration.html Maven / Gradle / Ivy

Go to download

Sanity4J was created to simplify running multiple static code analysis tools on the Java projects. It provides a single entry point to run all the selected tools and produce a consolidated report, which presents all findings in an easily accessible manner.

There is a newer version: 1.8.2
Show newest version


AccessorMethodGeneration

AccessorMethodGeneration

When accessing a private field / method from another class, the Java compiler will generate a accessor methods with package-private visibility. This adds overhead, and to the dex method count on Android. This situation can be avoided by changing the visibility of the field / method from private to package-private.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.design.AccessorMethodGenerationRule

Example(s):


public class OuterClass {
    private int counter;
    /* package */ int id;
    
    public class InnerClass {
        InnerClass() {
            OuterClass.this.counter++; // wrong accessor method will be generated
        }
        
        public int getOuterClassId() {
            return OuterClass.this.id; // id is package-private, no accessor method needed
        }
    }
}
 




© 2015 - 2024 Weber Informatics LLC | Privacy Policy