基本Q. [英] basic Q

查看:49
本文介绍了基本Q.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var myString = new String(" Hello world");

var myString =" Hello world" ;


两者没有区别吗?两者都创建了一个String obj

对吧?

var myString = new String("Hello world") ;
var myString = "Hello world" ;

There is NO difference between the two right ? both creates a String obj
right ?

推荐答案

Boobie写道:
var myString = new String(" Hello world");
var myString =" Hello world" ;

两者没有区别吗?


是的。

都创建一个String obj吧?
var myString = new String("Hello world") ;
var myString = "Hello world" ;

There is NO difference between the two right ?
Yes there is.
both creates a String obj right ?




第一个创建一个String对象并为该对象分配一个引用

到一个变量,第二个将一个字符串原始值赋给一个

变量。


Richard。



The first creates a String object and assigns a reference to that object
to a variable, the second assigns a string primitive value to a
variable.

Richard.


Richard Cornford写道:
Richard Cornford wrote:
Boobie写道:
Boobie wrote:
var myString = new String(" Hello world");
var myString =" Hello world" ;

两者没有区别吗?
var myString = new String("Hello world") ;
var myString = "Hello world" ;

There is NO difference between the two right ?



是的。


Yes there is.

两者都创建一个String obj吧?
both creates a String obj right ?



第一个创建一个String对象并将该对象的引用分配给一个变量,第二个将一个字符串原始值赋给一个<变量。

理查德。


The first creates a String object and assigns a reference to that object
to a variable, the second assigns a string primitive value to a
variable.

Richard.




这在实践中意味着什么?有性能考虑吗?


另外,当你使用第一种方法(new String(''Hello World''))时,会创建

一个字符串原语传递给String构造函数,

通过实际创建两个对象(即使原语只是临时(如果是)
)? />

Kevin N.



What does that mean in practice? Is there a performance consideration?

Also, when you use the first method (new String(''Hello World'')), does
that create a string primitive that is passed to the String constructor,
there by actually creating two objects (even if the primitive is only
temporary (if it is))?

Kevin N.




" Richard Cornford"

"Richard Cornford"
首先创建一个String对象并将该对象的引用分配给变量,第二个将字符串原始值赋给
变量。
The first creates a String object and assigns a reference to that object
to a variable, the second assigns a string primitive value to a
variable.




谢谢

所以当你(在什么情况下)使用一种形式与另一种形式时?



thanks
so when (under what circumstances) would you use one form vs the other ?


这篇关于基本Q.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆