thanks for all answers, they are very useful for me.
so far I worked on this issue and here is a code which can accept customized values for enum.
public class X {
private enum Solutions{
A (new double [] {1.5, 1.8, 1.9, 2.3, 2.7, 3.0} ),
B (new double [] {1.2, 1.8, 1.9, 2.4, 2.9, 3.1} ),
C (new double [] {1.3, 1.7, 0.9, 1.4, 2.2, 3.1} ),
D (new double [] {1.2, 1.4, 1.5, 2.6, 1.9, 3.1} ),
E (new double [] {1.4, 1.7, 1.8, 1.9, 2.3, 2.9} ),
CUSTOM (new double [] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0} );
private double[] val;
private Solutions (double[] pVal) {
val = pVal;
}
public double[] getVal(){
return this.val;
}
public void setVal(double[] pVal){
val = pVal;
}
}
public X() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args){
Solutions a = Solutions.A;
System.out.println("enum Solution A at index 0 is: " + a.getVal()[0] );
Solutions custom = Solutions.CUSTOM;
System.out.println("enum Solution Custom at index 0 is: " + custom.getVal()[0] );
double[] custArray = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
custom.setVal(custArray);
System.out.println("enum Solution Custom at index 0 after modification is: " + custom.getVal()[0] );
}
}
now my final question related to this issue is:
is there automated way to force accepting only double[] with length = 6 (specific length array)
or i have to check it by myself?
lets say ... is there any way to write member variable of enum like this:
private double[6] val;
instead of
private double[] val;