cloneable Questions

2

Solved

I couldn't find any material on Google saying about the use of Cloneable records. I was thinking of something like this: record Foo() implements Cloneable { public Foo clone() {...} } Is it a goo...
Arin asked 30/4, 2021 at 13:15

6

Solved

I'm trying to understand what's happening underneath the clone() method in java, I would like to know how is better than doing a new call public class Person implements Cloneable { private Strin...
Anatropous asked 25/2, 2015 at 17:29

3

Solved

I'm writing a class in which I have to override the clone() method with the infamous "super.clone() strategy" (it's not my choice). My code looks like this: @Override public myInterface clone() ...
Cordwain asked 19/12, 2015 at 21:41

5

Solved

So, I've been reading on Design Patterns and the Prototype Patterns confuses me. I believe one of the points of using it is avoiding the need for using the new operator. Then I look at this example...
Petrol asked 20/6, 2013 at 0:25

2

Solved

My question is about how to implement the classic ICloneable interface in such a way that it won't lead to inadvertent object-slicing when a future programmer isn't paying close attention. Here's a...
Diadromous asked 8/8, 2019 at 4:51

3

Solved

I came across some class code that implements Clonable, the documentation states: A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that me...
Jobless asked 12/5, 2013 at 13:6

8

Solved

Question: package GoodQuestions; public class MyClass { MyClass() throws CloneNotSupportedException { try { throw new CloneNotSupportedException(); } catch(Exception e) { e.printStackTrace()...
Austronesia asked 25/2, 2011 at 10:46

3

Solved

I wrote a program that has the trait Animal and the struct Dog implementing the trait. It also has a struct AnimalHouse storing an animal as a trait object Box<Animal>. trait Animal { fn sp...
Message asked 20/5, 2015 at 15:0

4

Solved

If I have: class foo implements Cloneable and then do: bar = new foo(); bar.clone(); I get a shallow copy without needing to write any bar.clone() code like I normally would need to do when ...
Venn asked 1/7, 2009 at 5:17

9

Solved

I need to implement a deep clone in one of my objects which has no superclass. What is the best way to handle the checked CloneNotSupportedException thrown by the superclass (which is Object)? A ...
Moscow asked 24/2, 2010 at 14:41

3

Solved

I was looking for tutorials online about java cloning, but only found the disadvantages to clone() and nothing about the advantages. I would like to know some of the advantages of using Java clone(...
Borax asked 2/5, 2013 at 1:57

7

Solved

I am trying to clone a object of class Integer, which does implement the cloneable inteface. Integer a = new Integer(4); Integer b = a.clone(); I know there are work arounds for this, but I mu...
Platform asked 28/4, 2011 at 6:55

2

Solved

What is the best tool for java's clone() method generation in Eclipse Galileo available from repositories? What is the reason, that prevents Eclipse developers from including this tool in standard...
Unsuccessful asked 5/7, 2010 at 15:18

6

Solved

I would like to know the following: Cloneable means we can have a clone or a copy of objects, by implementing the Cloneable interface. What are the advantages and disadvantages of doing that? How ...
Unsettle asked 2/11, 2010 at 20:35

2

Solved

Cloneable in Java is inherently broken. Specifically, my biggest problem with the interface is it expects a method behavior that doesn't define the method itself. So if traversing through a Cloneab...
Kadner asked 6/12, 2015 at 20:1

1

Solved

When Joshua Bloch mentions that Cloneable interface is broken in Java, why is the Prototype pattern, which uses clone() method to facilitate object creation, not considered an anti-pattern in...
Obliging asked 11/9, 2015 at 15:26

5

i want to clone a given object. if i do this public class Something{ Object o; //set in the constructor public Something(Object o){ this.o = o;} public Something clone() throws CloneNotSuppor...
Colous asked 21/6, 2015 at 11:49

3

Solved

I'm trying to implement a Clonable class with the CRTP. However, I need to have abstract class that have a pure virtual clone method, overridden by child classes. To make this happen, I need the cl...
Predetermine asked 15/5, 2015 at 5:22

3

Solved

public class test implements Cloneable { @Override public test clone() { return (test) super.clone(); } public static void main(String[] args) { new test().clone(); } } I get error: unrep...
Chronopher asked 29/1, 2015 at 12:0

3

Solved

It is commonly understood that Cloneable interface in Java is broken. There are many reasons for this, which I will not mention; others already did it. It is also the position of Java architects th...
Drawl asked 16/10, 2014 at 7:48

4

Solved

I was reading Joshua Bloch's Effective Java. In there he talks about not using the Clonable interface. I'm a bit of a noob so my question is, whats a use-case for when cloning would be required in ...
Minhminho asked 14/5, 2014 at 2:34

3

Solved

I have a Queue q1, that is implemented as a LinkedList, and I want to define a Queue q2, that is a separate, but identical identical instance of Queue q1. How do I do that since Queue does not imp...
Permissible asked 10/4, 2014 at 8:3

6

Solved

I know that clone() is a protected method, but "protected" means that it is accessible for all subclasses of particular class. Any Java class is a subclass of Object, so what is the reason f...
Aliphatic asked 14/8, 2013 at 18:58

3

Solved

I read lots of threads about the clone() method of Object and the Cloneable Interface but I couldn't find a legitimate answer to my question. Long story short: What I figured out is that Ob...
Laveta asked 1/5, 2013 at 9:19

4

Solved

I need to equip my class with polymorphic cloning (deep copy), i.e. I need something like this to work: SuperType original = new SubType(); SuperType copy = original.clone(); where original.clon...
Cinchonize asked 3/4, 2013 at 14:28

© 2022 - 2024 — McMap. All rights reserved.