I would like to do something like this:
public class Foobar {
@Tag final private int foo;
@Tag final private int bar;
@Tag final private int baz;
@Tag final private int quux;
static private final TagValidator validator =
TagValidator.autoGenerate(Foobar.class);
public Foobar(Something something)
{
validator.validate(something);
this.foo = something.method1();
this.bar = something.anotherMethod();
this.baz = something.someOtherMethod();
this.quux = something.yetAnotherMethod();
}
... other methods ...
}
where it TagValidator.autoGenerate()uses markup analysis + annotations to get all the members of my Foobar class that have been tagged @Tagand do some rude painstaking boring things that I will need to do for several classes.
My question is: will these members be seen in the order in which they are declared? I agree that it would be safer to do this:
public class Foobar {
@Tag(0) final private int foo;
@Tag(1) final private int bar;
@Tag(2) final private int baz;
@Tag(3) final private int quux;
...
}
but I feel lazy :-)
Also, is it possible to have a class and annotation with the same name?
source
share