I had recently asked question on stackoverflow, although I got the solution, but I am not able to understand the way the code is written there. This is the code
public class User {
@NotNull(message = "First name can't be blank", groups = {Step1.class, FinalStep.class})
private String firstName;
@NotNull(message = "Last name can't be blank", groups = {Step1.class, FinalStep.class})
private String lastName;
@NotNull(message = "Email can't be blank", groups = {Step1.class, FinalStep.class})
private String emailAddress;
@NotNull(message = "Please provide a valid address", groups = {Step2.class, FinalStep.class}) // this one also
private Address address;
public interface Step1 {} // this one
public interface Step2 {}// this one
public interface FinalStep {} // this one
}
the original post is Link to original post
- The first question which comes in my mind why interface is declared in the class.
- Second what is the advantage of doing this type of coding
- and last where I can use this approach
Finally if it is useful, can you name this approach if not then any link which can explain about this more clearly.