我最近问过stackoverflow问题,虽然我得到了解决方案,但我无法理解代码编写的方式。这是代码
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
}
最后,如果它有用,你可以命名这种方法,如果没有,那么任何可以更清楚地解释这个问题的链接。
答案 0 :(得分:1)
我发现这个搜索SO: Why should we declare an interface inside a class?
因此,在处理某些层次结构时,您可以描述一个"嵌套" 接口,将由包装类实现 子类。
在JDK中,最重要的例子是Map.Entry inner 接口,在Map接口中定义并由各种实现 HashMap,LinkedHashMap等的方法......