The methods getMessage()
in MessageSource.java accept their arguments as an array of Object
s:
https://github.com/spring-projects/spring-framework/blob/8047a0bb784087ae9699680017ebb5a43d77a5b7/spring-context/src/main/java/org/springframework/context/MessageSource.java#L74
By changing the type of args
to be a vararg variable instead of being an explicit array, users can call the method without having to create an array and pass it around. Also messages often do not require any arguments so this change makes it easy to call the methods without arguments (instead of passing null or an empty array).
What I'm suggesting is something like this:
String getMessage(String code, Locale locale, Object... args) throws NoSuchMessageException;
Affects: \<5.1.2.RELEASE>
Comment From: mahozad
Just a reminder. It would be great if this was triaged.
Comment From: snicoll
Thanks for the suggestion but it's quite common that arguments are specified as an array. I understand that you'd feel it more convenient but it's just syntaxic sugar and a vararg of Object
in particular makes an odd method signature as it accepts anything.