Java implementation class or import class

Internally for Java, what is better, or what is best, or what is standard: implementing a class with constants or using dot notation?

Example:

Option 1:

import com.myproject.Constantes;

public class myClass {
    myClass() {
        System.out.println("Math: " + Constantes.PI);
    }
}

Option 2:

import com.myproject.Constantes;

public class myClass implements Constantes {

    myClass() {
        System.out.println("Math: " + PI);
    }
}

Which is better? Why? Mvj usage, resources, speed?

Solution

If constants is purely a collection of constants (as the name suggests) and does not define functions that need to be exposed in MyClass, then a) it should not be an interface, and b) you should not implement / extend it Import and use it, such as option 1

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>