In answer to the question implied by your title Should we use Enums in java with different data types? I must answer a resounding no because actually you can't. Enums have their own data type and each enum
is essentially a new data type. This is where one of their their biggest powers lie - they can be strongly type checked at compile time.
The body of your question is a little unfair - firstly you would never consider replacing non-finals with enums so let us pretend you posted:
class A {
public static final int A = 1;
public static final int B = 2;
public static final String c = "RADIUS";
public static final String d = "LENGTH";
}
May I also take a few liberties with your naming and make the sample a little more realistic:
class A {
public static final int ONE = 1;
public static final int TWO = 2;
public static final String RADIUS = "RADIUS";
public static final String LENGTH = "LENGTH";
}
Now - the conversion to enum
comes naturally:
class A {
enum Number {
ZERO,
ONE,
TWO;
}
enum Measure {
RADIUS,
LENGTH,
WEIGHT;
}
}
I have added further values to demonstrate the resultant versatility.