Name: mr33420 Date: 02/18/2000
The Java programming language provides no convenient way to pass a variable
number of arguments to a method, similar to the varargs feature of C or the
&rest keyword of Common Lisp. This feature is extremely useful in GUI APIs, in
constructing and manipulating collections, and in APIs for formatted output.
One of the goals of the New I/O project, for example, is to provide a simple
API for formatted textual output similar to the well-known printf procedure of
the standard C library. Developers have been asking for this feature for
years; adding it will make Java that much more attractive an alternative to C,
C++, and Visual Basic.
The central method of such an API accepts a format string followed by some
arguments. The exact number of arguments required depends upon the content of
the format string. Ideally we'd like to be able to write something like:
Formatter f = new Formatter(System.out);
f.fmt("%d bytes in %d seconds (%.2f KB/s)\n",
nbytes, seconds, ((double)(nbytes / 1024) / (double)seconds));
The Java programming language, as presently defined, does not allow this.
This feature is being developed as JSR-065.