Похожие чаты

Are there Copy constructors in Java ? if yes , how

can we implement them ?
(without pointers )

6 ответов

11 просмотров

No, there no copy constructors in java. Simply because there's no use-case for copy-constructors in java by design, unlike in C++. In java absolutely every object is always created in heap. And stack is for primitive values and pointers only. So technically it's impossible in java to create object on stack. That's why when you're either "copying" objects or pass them as parameters, *pointers/references* are copied, not the objects. Always. That's why there's no any use-case for copy-constructors in java, in places where C++ would call copy-constructor, java simply copies *pointer* (int primitive). There are 2 mechanisms similar to copy-constructors in mechanics, but not in usage. - copy-constructor similar in its purpose to "prototype" design pattern, though roles of this pattern are inverted in case of constructor; most well-known example - collections, almost any collection/map implementation allows to create new collection by copying existing one; constructors look like public ArrayList(Collection collection) {... - Object.clone() + Cloneable interface - stone age language-level implementation of same "prototype" design pattern, though it's not popular nowadays. Not sure if it was really popular ever. Might be in early years of java.

Do you want shallow copy or deep copy? But as others have answered above my message there are no copy constructors in Java

♧Šmøķê♧ ×͜×- Автор вопроса
Dmytro Buryak
No, there no copy constructors in java. Simply bec...

Got it , Thank you , Also I would like to ask are default and no argument constructors are same ?

♧Šmøķê♧ ×͜×- Автор вопроса
David Hu
Do you want shallow copy or deep copy? But as oth...

Nah I just wanted to confirm there isn't copy constructors that's all .👍 I got that now .

Those questions give me a weird feeling of exam or interview questions. Why are you asking such things?

♧Šmøķê♧ ×͜×- Автор вопроса

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта