由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - copy constructor都什么时候be called啊
相关主题
how to copy an Object?How to know the size of a java object ?
跪求大牛指点Java,看不懂什么意思。怎样用class的string type name 动态生成object?
what's inside an java object?这段是什么语法?
Java里面有没有可能写个带generic parameter的class对built-in type也适用?说说clone咋违反了类继承的原则来的?
Java复制objectimmutable list
Static就是个混球[合集] 问一下这个cast在java里是怎么work的
synchronized method does lock the object that passed into the method as a parameter?[合集] 谁能解释一下这里的protected specifier
有熟悉Java Reflection的吗return type, map or object
相关话题的讨论汇总
话题: copy话题: java话题: chick话题: c++
进入Java版参与讨论
1 (共1页)
r*******w
发帖数: 121
1
parameter passing...
还有什么时候?
m******t
发帖数: 2416
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...
: 还有什么时候?

r*******w
发帖数: 121
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-)

m******t
发帖数: 2416
4

I would think so.

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

F****n
发帖数: 3271
5
Is there any copy constructor in Java? What you guys are talking about?

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

s******e
发帖数: 63
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?
r*******w
发帖数: 121
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.

e***g
发帖数: 158
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.

F****n
发帖数: 3271
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.

r*******w
发帖数: 121
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.

n*****k
发帖数: 123
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.

1 (共1页)
进入Java版参与讨论
相关主题
return type, map or objectJava复制object
传递一个object reference,如何防止更改object?Static就是个混球
Netbean duplicate class errorsynchronized method does lock the object that passed into the method as a parameter?
Re: 谁有Java或Oracle的毒招 ?有熟悉Java Reflection的吗
how to copy an Object?How to know the size of a java object ?
跪求大牛指点Java,看不懂什么意思。怎样用class的string type name 动态生成object?
what's inside an java object?这段是什么语法?
Java里面有没有可能写个带generic parameter的class对built-in type也适用?说说clone咋违反了类继承的原则来的?
相关话题的讨论汇总
话题: copy话题: java话题: chick话题: c++