ecoCode icon indicating copy to clipboard operation
ecoCode copied to clipboard

[S90-JAVA] Avoid use of static in interface

Open ggeoffroy68 opened this issue 3 years ago • 4 comments

ggeoffroy68 avatar Dec 03 '22 09:12 ggeoffroy68

Bad usage:  

    public interface Color {
        public static final int RED = 0xff0000;// Noncompliant
        public static final int BLACK = 0x000000;// Noncompliant
        public static final int WHITE = 0xffffff;// Noncompliant
    }

Good usage:

    public enum Color {
        RED,// Compliant
        BLACK,// Compliant
        WHITE;// Compliant
    }

ggeoffroy68 avatar Dec 03 '22 09:12 ggeoffroy68

Hello @ggeoffroy68, I have questions about this new rule. I agree with you public static final keywords are useless. For example, we can have an interface with variables like int RED = 0xff0000;. But why is it a "green" rule ? And why enum usage is better that an interface with variables ? maybe one enum is better of one interface + 3 variables ? Do you have a scientific paper about this subject ?

thank you.

dedece35 avatar Dec 03 '22 18:12 dedece35

Hi @ggeoffroy68 , we are migrating this repo to a new one : please see https://github.com/green-code-initiative/ecocode/pull/7

dedece35 avatar Dec 05 '22 14:12 dedece35