Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法限制方法只采用枚举的某些成员。假设您列举了军事和入伍军衔。如果我想要一个只能获得军官级别的功能而另一个只能获得入伍级别的功能,我认为在 Java 中没有办法做到这一点,是吗?
您唯一的选择是使用不同的枚举,因为将枚举作为参数的方法将在编译时采用其任何值。
IDE 有助于打字。