Redian新闻
>
copy constructor都什么时候be called啊
avatar
copy constructor都什么时候be called啊# Java - 爪哇娇娃
r*w
1
parameter passing...
还有什么时候?
avatar
m*t
2

Since you are posting on Java board, the answer would be "no, it doesn't
happen at parameter passing". 8-)

【在 r*******w 的大作中提到】
: parameter passing...
: 还有什么时候?

avatar
r*w
3
oops...you are right~~~
那copy constructor就没什么用了,其实?
除非我自己call?

【在 m******t 的大作中提到】
:
: Since you are posting on Java board, the answer would be "no, it doesn't
: happen at parameter passing". 8-)

avatar
m*t
4

I would think so.

【在 r*******w 的大作中提到】
: oops...you are right~~~
: 那copy constructor就没什么用了,其实?
: 除非我自己call?

avatar
F*n
5
Is there any copy constructor in Java? What you guys are talking about?

【在 m******t 的大作中提到】
:
: I would think so.

avatar
s*e
6
Copy constructor is the constructor for objects of class T which takes as
its single argument a reference to another object of class T. This
constructor builds a copy of the object passed by reference--hence the
name copy constructor.
you can define constructor method in Java class to mimic C++ copy constructor.

【在 F****n 的大作中提到】
: Is there any copy constructor in Java? What you guys are talking about?
avatar
r*w
7
this is a pretty good news...
then i control everything ;-) no need to worry deep copy and shallow copy
anymore...

【在 m******t 的大作中提到】
:
: I would think so.

avatar
e*g
8
there is no concept/support/usage of copy constructor; people rarely
copy objects in java anyways; your constructor is just a normal one.
if copy is indeed needed, clone() is the official way. it at least
has the advantage of polymophism, so that
Chick chick = ..;
Bird bird = chick;
bird.clone() returns a chick.

【在 s******e 的大作中提到】
: Copy constructor is the constructor for objects of class T which takes as
: its single argument a reference to another object of class T. This
: constructor builds a copy of the object passed by reference--hence the
: name copy constructor.
: you can define constructor method in Java class to mimic C++ copy constructor.

avatar
F*n
9
这绝对属于拿C++的概念来乱套, C++ copy constructor, 只有在和赋值联系起来才
有意义,根本就不APPLY IN JAVA。

constructor.

【在 s******e 的大作中提到】
: Copy constructor is the constructor for objects of class T which takes as
: its single argument a reference to another object of class T. This
: constructor builds a copy of the object passed by reference--hence the
: name copy constructor.
: you can define constructor method in Java class to mimic C++ copy constructor.

avatar
r*w
10
clone is a good idea...
however, in some cases i need shallow copy and in other cases i need deep
copy...therefore one method is not enough ah ;-)
either a copy constructor...or either a "copy" method is needed...

constructor.

【在 e***g 的大作中提到】
: there is no concept/support/usage of copy constructor; people rarely
: copy objects in java anyways; your constructor is just a normal one.
: if copy is indeed needed, clone() is the official way. it at least
: has the advantage of polymophism, so that
: Chick chick = ..;
: Bird bird = chick;
: bird.clone() returns a chick.

avatar
n*k
11

come on, in C++, you still have to program a lot in order to have deep copy,
same thing in java, you have to override clone() method to have a deep copy
as you want.

【在 r*******w 的大作中提到】
: clone is a good idea...
: however, in some cases i need shallow copy and in other cases i need deep
: copy...therefore one method is not enough ah ;-)
: either a copy constructor...or either a "copy" method is needed...
:
: constructor.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。