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

前端 未结 23 2941

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:27

    I would just add that Java has Copy constructors...

    Well, that's an ordinary constructor with an object of same type as argument.

提交回复
热议问题