Tanya Bear Tanya Bear - 1 year ago 139
Java Question

Constants in Interface

I know there were a lot of questions about putting constants into interfaces, and that is a bad practice.

But I have a question, what if I have a class, where I want to define some sets of constants, but I want to have them in groups, is it a bad practice to have interface/class inside a class and define constants in there, so my constants are grouped?


public class MyClass{

public final class A {
public static final String A = "a" ;
public final class B {
public static final String B = "b";

Answer Source

Yes you can have nested class to group the constants. It's really not a bad practice.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download