I wrote a class like this and named it Solution.java
.
public class Solution {
public static void main(String[] args) {
System.out.println(args.length);
}
}
BUt when I run it in Terminal, I got a result like this:
> /Users/WangWei java Solution *
18
> /Users/WangWei
Why 18?
That's probably the number of files in your working directory.
The result of *
is not specific to Java. It is specific to the environment you are working in, i.e. the working directory and the kind of shell (Windows command prompt, bash, ...) you are using to run the java command. This is because the shell processes and evaluates the command line before starting the process. It replaces the *
.
To preserve a *
as a command line argument, you need to quote it:
java Solution '*'
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