Main method in Java have the String[] as input parameter to the main method, but i want to pass object as a parameter. Java and all command line parametrized languages accept only String array of arguments which make sense as our ability to call using command line gives us the ability to enter text that could be represented by String object in Java
This is how we used to have a method like:
public static void main (String[] args) {
for (String text: args) {
System.out.println(text);
}
}
If we need to pass integer value, we need to use parsing method to obtain the numeric value from it.
try {
Arg = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
System.err.println("Number format mismatch");
}
What if we need to pass a whole object as an argument to the class?
Regards