In my program, I have a method which is below;
private void foo(String title, String[] subtitles, int ... subtitleValues)
My requirement is ;
- number of subtitles and subtitleValues must be equal. User can send any number of subtitles and subtitle values but as I said equal number of subtitles and subtitleValues.
I don’t want to take both arguments and check their counts in foo function and say your table can not be created because of unequal subtitles and subtitleValues. What I want is; prevent user to send unequal arguments. How can I do that?
Thanks in advance
PS : I didn’t find a proper title, so if you have, please feel free to change it.
You can’t do it like this. What you can do to make your method harder to call wrongly is to use a fluent API for a builder like this:
I left out the implementation for brevity. Then you can call it like this: