How string class difference from other classes?

后端 未结 4 678
不思量自难忘°
不思量自难忘° 2021-01-21 07:37

We can do:

String string = \"ourstring\";

But we can\'t create objects like this for user defined classes:

UserClass uc=\"\";

4条回答
  •  一向
    一向 (楼主)
    2021-01-21 08:15

    "" is syntactic sugar for returning a String object from the interned String pool.

    Consider it as the exception rather than rule. Regular object assignments need to take the form

    MyObject myObject = new MyObject();
    

提交回复
热议问题