Home Segments Top Top Previous Next

578: Sidetrip

Because all vector elements must be instances, you might wonder how you could possibly make a vector of, say, int values, inasmuch as int values are not instances of a class.

The answer is that you use an instance of the Integer class. All such instances have an instance variable to which an integer is assigned. Because instances of the Integer class are instances, in contrast to int values, those instances are valid vector elements.

Because the purpose of Integer instances is to surround int values, in a way that enables those int values to enter into vectors, Integer instances are called wrappers.

The Long, Float, and Double classes serve as wrapper classes for other arithmetic types.