Your main method needs to match
public static void main(java.lang.String[] args){ ... }
If you create your own String
class in the same package where the class with your main method is, it will become
public static void main(your.own.package.String[] args){ ... }
which is valid, but will not allow the runtime launcher to find a main method anymore, since it expects java.lang.String[]
as parameter.
The classes from java.lang
are imported automatically by default, so you don't need an explicit import
statement - that probably made it even more confusing to you.
As a rule of thumb, I would avoid to name my own classes the same as classes from the Java Runtime, whenever possible - especially from java.lang
.
See also the JLS: Chapter 7. Packages:
A package consists of a number of compilation units (§7.3). A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.