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?
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?
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.
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
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.
有意义,根本就不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
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.
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
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.
相关阅读
谁来帮忙推荐一本学习Maven的书请goodbug和诸位大牛帮忙:Swing 的lookandfeel 设置Java Concurrency in Practise, 哪里有?新手请教 java applet+html 入门级问题java 还在改进吗?java vs ruby on rail for e-commerce website?请教一个vignette vcm问题eclipse how to remember a code location and jump back?Java如何实现自动消失的消息框?几个认证的问题Recommend a Book about Algorithm? (转载)anybody working on Cassandra?一个多线程问题Oracle收购Sun后 最新公布的产品策略,怀念SUNhow to map one to many relation for a single table in hibe请问公司里用Java主要干啥?探讨一个java, sql设计问题SOAP over JMS with CXF frame?xslt: how to replace character新手求问:学JavaWeb和J2EE有什么好教材?