Sharkysoft home

lava.clib.stdarg
Class Va_list

java.lang.Object
  |
  +--lava.clib.stdarg.Va_list

public class Va_list
extends java.lang.Object

Syntactic sugar for variable argument lists.

Details: Va_list is an adaptation of the va_list array variable used in C programs that implement variable argument lists. (These programs often include the stdarg.h header file.) In this Java port, Va_list is made available as a convenient interface for building variable argument lists, for use in functions that require them, such as Stdio.printf.

Since Java does not support variable-length and untyped argument lists, variable argument lists must be passed as Object arrays. This class exists solely to aid in the inline construction of such Object arrays.

The following three examples demonstrate how this class can be used in conjunction with the printf methods. Each example produces exactly the same output.

Although using Va_list to produce Object arrays can in some cases produce more readable code, in general it is not as efficient as other Object array construction techniques. Nevertheless, this class is available for those who are squeamish about constructing Object arrays on their own.

Compatibility note: Because of changes made by Sun to java.util.Vector in Java 1.2, this class can no longer inherit from Vector. This modification should not affect most programs that use this class, but some programs may require recompiling.

Since:
before 1998.02.19
Version:
1998.12.23

Constructor Summary
Va_list()
          Initializes a new instance whose final length is undetermined.
Va_list(int length)
          Initializes a new instance whose final length is known ahead of time.
 
Method Summary
 Va_list add(char c)
          Appends a char to the list.
 Va_list add(double d)
          Appends a double to the list.
 Va_list add(float f)
          Appends a float to the list.
 Va_list add(int i)
          Appends an int to the list.
 Va_list add(long l)
          Appends a long to the list.
 Va_list add(java.lang.Object o)
          Appends an Object to the list.
 Va_list add(short s)
          Appends a short to the list.
 java.lang.Object[] done()
          Converts the list to an Object array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Va_list

public Va_list()
Initializes a new instance whose final length is undetermined.
Since:
1998

Va_list

public Va_list(int length)
Initializes a new instance whose final length is known ahead of time.
Parameters:
length - intended length of argument list
Since:
1998
Method Detail

add

public Va_list add(java.lang.Object o)
Appends an Object to the list. (This method can be used to add any type of object, including Strings, to the list.)
Parameters:
o - object to be added
Since:
1998

add

public Va_list add(char c)
Appends a char to the list.
Since:
1998

add

public Va_list add(short s)
Appends a short to the list.
Since:
1998

add

public Va_list add(int i)
Appends an int to the list.
Since:
1998

add

public Va_list add(long l)
Appends a long to the list.
Since:
1998

add

public Va_list add(float f)
Appends a float to the list.
Since:
1998

add

public Va_list add(double d)
Appends a double to the list.
Since:
1998

done

public java.lang.Object[] done()
Converts the list to an Object array.
Since:
1998

Sharkysoft home