I can not find documentation on this issue.
In some Lists and Maps order of the elements is random and does not coincide with the order in which they were added to the list / map. Is this true for var args, or are they received in the same order in which they were sent?
For example, I have a form validation method that takes a field name and a list of vararg rules. If I set the rules: Rules.INT, Rules.MAX.arg(100) , then I would like the Rules.INT rule Rules.INT be checked first before the Rules.MAX rule is Rules.MAX , because Rules.MAX assumes that this value is a valid integer. Therefore, if Rules.INT fails, then Rules.MAX will not be called - however, if varargs are received in a random order, then Rules.MAX can be called before Rules.INT anyway and can then throw an exception if the value is not is an integer that I don't want.
Edit: Here is my method with var args, for clarification:
public boolean validate(String name, Rule... rules) { String value = getValue(name); for (Rule rule : rules) { if (! rule.match(value) ) return false; } return true; }
Now, if I called this method with: validate("age", Rule.INT, Rule.MAX.arg(100) ) , can I be sure that Rule.INT will be repeated / checked before Rule.MAX in the method validate() ?
source share