I'd like to create a class with about 60 fields of type double inside. Then I need to create different instances of this class, valuing through the constructor only some of these fields (about 4-5 fields), leaving the others as default (0).
The problem is that I don't want to have a 60 parameters constructor, since it would be a waste of time to fill all the required fields. Furthermore, I don't want to create public methods to set fields value one by one.
I was thinking about java Annotation, somenthing like
public @interface MyAnnotation{
public double f1() default 0;
public double f2() default 0;
public double f3() default 0;
...
public double f60() default 0;
}
so that I can then specify only the parameters I need
@MyAnnotation(f1=2.1 , f48=3.5)
Anyway, I don't have much experience on that and I'm not sure it can cope with my needs. Broadly speaking, my object would be to have something like:
MyClass c1 = new MyClass(f1=2.1 , f48=3.5);
MyClass c2 = new MyClass(f4=5 , f30=12.9);
public class MyClass{
double f1;
double f2;
double f3;
...
double f60;
}
Is there a way to get somenthing similar also with class constructors?
P.S. I'm not a programmer but I'm quite aware of Java reflections, so no problem if they would be required.