Historical reasons: the PrintStream
class exists since Java 1.0, long before autoboxing was added (in 1.5).
Autoboxing is what would enable you to pass a primite type to print(Object o)
. Without it PrintStream
had to implement an overload for each primitive type separately.
By the way, the implementations of print(..)
for primitive types is more like:
public void print (int o) {
print(String.valueOf(o));
}
... and the implementation of String.valueOf(..)
basically delegates to methods in wrapper classes, such as Integer.toString(int)
and Long.toString(long)
. You can read the source code at docjar.