I am trying to have a method that can take in ANY TYPE as a parameter (Object, int, boolean, ArrayList, etc.). Here is a very simple method to illustrate what it would be trying to do:
public void printAnything(Type arg0) {
System.out.println(arg0);
}
And what I am asking is, what would replace Type in that method?
In your specific example, Object would fit well because PrintStream#println(Object obj) would print the string representation (using String#valueOf(Object)).
When you pass a primitive value, it will be automatically boxed into its wrapper type, e.g an int would be converted to java.lang.Integer which extends Object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With