$ cat Const.java
public class Const {
String Const(String hello) {
return hello;
}
public static void main(String[] args) {
System.out.println(new Const("Hello!"));
}
}
$ javac Const.java
Const.java:7: cannot find symbol
symbol : constructor Const(java.lang.String)
location: class Const
System.out.println(new Const("Hello!"));
^
1 error
解决方案
What you've defined isn't actually a constructor, but a method called Const. If you changed your code to something like this, it would work:
Const c = new Const();
System.out.println( c.Const( "Hello!" ) );
If no specific constructor is explicitly defined, the compiler automatically creates a no-argument constructor.