Name
Formattable
Synopsis
This
interface should be implemented by
classes that want to interact with the Formatter
class more intimately than is possible with the
toString
method. When a
Formattable
object is the argument for a
%s
or %S
conversion, its
formatTo( )
method is invoked rather than its
toString( )
method. formatTo( )
is responsible for formatting a textual representation of the object
to the specified formatter
, subject to the
constraints imposed by the flags
,
width
, and
precision
arguments.
The flags
argument is a bitmask of zero or
more FormattableFlags
constants. Each flag
provides information about the format specification that resulted in
the invocation of formatTo( )
.
FormattableFlags.ALTERNATE
indicates that the
#
flag was used and that the
Formattable
should format itself using some
alternate form. The interpretation of the alternate form is entirely
up to the Formattable
implementation.
LEFT_JUSTIFY
means that the -
flag was used and that the Formattable
should pad
its output on the right, instead of on the left.
UPPERCASE
indicates that the %S
conversion was used instead of %s
and the
Formattable
should output uppercase characters
instead of lowercase.
The width
and
precision
arguments specify the width and
precision specified along with the %s
format
specifier, or -1 if no width and precision are specified. The
Formattable
object should treat these values the
same way that Formatter
does. The text to be
output should first be truncated to fit within
precision ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.