Java Reference
In-Depth Information
public
public
int
int
setValue
(
int
int
i
) {
value
=
i
;
return
return
value
;
}
public
public
int
int
getValue
() {
return
return
value
;
}
public
public
String
toString
() {
return
return
Integer
.
toString
(
value
);
}
public
public static
static
String
toString
(
int
int
val
) {
return
return
Integer
.
toString
(
val
);
}
public
public static
static
int
int
parseInt
(
String str
) {
return
return
Integer
.
parseInt
(
str
);
}
}
See Also
As mentioned, this use of my
MutableInteger
class could be replaced with the standard
class
ParsePosition
. However,
MutableInteger
has other uses: it makes a fine in-memory
counter in a servlet or other application. For immutable argument passing, one solution is to
use Java's typesafe enumeration pattern (
enum
s, which have been in the language for a dec-
ade; see
Using Typesafe Enumerations
).
Using Typesafe Enumerations
Problem
You need to manage a small list of discrete values within a program.
Solution
Use the Java
enum
mechanism.