Annotations for Custom Validation in Java


Create custom annotations to specify metadata that can be used to enforce validation rules or other constraints.

Source Code

@interface ValidAge {
    int value() default 18;
}

class Person {
    @ValidAge(21)
    private int age;

    // Constructor, getter, and setter
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments