In past releases, a method that took an arbitrary number of values required you to create an array and put the values into the array prior to invoking the method.
It is still true that multiple arguments must be passed in an array, but the varargs feature automates and hides the process. Furthermore, it is upward compatible with preexisting APIs.
Public static String format(String pattern,
Object... arguments);
The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments. Varargs can be used only in the final argument position.
Much more simpler example here..
public class VarArgs {
public static void main(String[] args) {
String[] newArgs = {"a", "b", "c"};
vaMethod(newArgs);
}
public void vaMethod(String[] args) {
System.out.println("You gave me " + args.length + " args! Yay.");
}
}
You can declare it more easily, and not have to construct the array ahead of time:
public class VarArgs {
public static void main(String[] args) {
vaMethod("a", "b", "c");
}
public void vaMethod(String... args) {
System.out.println("You gave me " + args.length + " args! Yay.");
}
}
Ajax to JSR 168 Portlets
-
Good article on *Best Practices for Applying AJAX to JSR 168 Portlets
http://developers.sun.com/portalserver/reference/techart/ajax-portlets.html*
0 Comments:
Post a Comment