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()
...
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...
8
Solved
Question:
package GoodQuestions;
public class MyClass {
MyClass() throws CloneNotSupportedException {
try {
throw new CloneNotSupportedException();
} catch(Exception e) {
e.printStackTrace()...
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...
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 ...
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 ...
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(...
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...
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 ...
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...
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...
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 ...
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...
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...
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...
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...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.