Query about java code

79 views Asked by At

I was looking for Spring form validation tutorial Yesterday, an from one of those i found this lines

String message() default "{Phone}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};

the above code was for phone number field validation,If any one can explain those lines that will be helpful ,i am not asking anything about validation,( I am confuse because those are neither function nor instance as far as i think ) i never have seen these type of code in java before.

1

There are 1 answers

0
Evgeniy Dorofeev On

Those are elements of some annotation declaration, eg

@interface A {
    String message() default "{Phone}";
    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};

}

and this is how it can be used

@A(message = "Email", payload = {Payload.class})
class Test1 {
}

the above annotation will have default groups value = empty Class array