سؤال

Is there a way to restrict a method to only take certain members of an enumeration. Let's say you had an enumeration of military and enlisted ranks. If I wanted a function that only could take officer ranks and another that could only take enlisted ranks, I don't think there's a way to do that in Java, is there?

هل كانت مفيدة؟

المحلول

Your only option is to use distinct enums, as a method taking an enum as a parameter will take any of its values at compile time.

IDEs help with the typing.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top