I would like to make an alias of or an extended version of System.out.println()
for printing my variables of various types. How does one pass an argument with unknown type/class to a method?
public static void p(VariableType... args) {
System.out.println(args[0]);
// ...
}
You can use Object
.
public static void p(Object... args) {
System.out.println(args[0]);
// ...
}
Unless you want lots of lines in the output, you could do.
public static <PrintableToString> void p(PrintableToString... args) {
for(PrintableToString pts: args)
System.out.print(pts);
System.out.println();
}
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