Java Strings: “String s = new String(”silly“);”

前端 未结 23 2492

I\'m a C++ guy learning Java. I\'m reading Effective Java and something confused me. It says never to write code like this:

String s = new String(\"silly\");         


        
23条回答
  •  逝去的感伤
    2020-11-22 14:39

    You can't. Things in double-quotes in Java are specially recognised by the compiler as Strings, and unfortunately you can't override this (or extend java.lang.String - it's declared final).

提交回复
热议问题