Questions tagged [cloneable]

163 questions
0
votes
1 answer

Android - Class cloning not working

public class UserWord extends WordADT { public int WORD_STATUS; public int POINT_OF_WORD; public int COUNT_OF_WRONG_ANSWER; @Override public Object getClone() throws CloneNotSupportedException { return…
Hayrullah Cansu
  • 262
  • 5
  • 14
0
votes
1 answer

Cloneable and Comparable Interface

My Question is about Complex numbers in Java. I created a class performing several mathematical operations like addition, subtraction, multiplication & division successfully. But my problem is how to implement cloneable and comparable interfaces…
Kamal
  • 37
  • 2
  • 10
0
votes
0 answers

Effective Java item 11: Why clone can't call the constructor?

While explaining the item 11: Override clone() judiciously it says - The "only" way a superclass can provide this functionality is to return an object obtained by calling super.clone. If a clone method returns an object created by a constructor, it…
Saurabh Patil
  • 4,170
  • 4
  • 32
  • 33
0
votes
1 answer

What is the right way to use object cloning?

This is the way I understand object cloning with an example : import java.util.GregorianCalendar; public class CloneType1 { public static void main(String[] args) { GregorianCalendar obj = new GregorianCalendar(); GregorianCalendar…
CoDerus
  • 151
  • 1
  • 1
  • 4
0
votes
1 answer

Clone function inside the same class

I am making some simulations with java. I am trying to simulate, several steps ahead, a node of a tree and then discard all changes and go back to original state. But the clone() does not return me proper resuts. Node class: public class TreeNode…
Emka
  • 340
  • 6
  • 16
0
votes
0 answers

Cloning complex objects with Cloneable interface

i'm trying to clone a complex object with Cloneable interface. I have a super object called Resource, that haves two fields: public class Resource implements Cloneable{ protected String name; protected boolean isOnline; …
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
0
votes
4 answers

Undesrstanding clone method for arrays

I've learnt that for arrays the clone method is well-behaved and we can use it. But I thought that the type of the elemetns the arrays hold should have implemented Cloneable interface. Let me provide some example: public class test { public…
stella
  • 2,546
  • 2
  • 18
  • 33
0
votes
3 answers

Java copy constructor and clone doesnt work

public class Stav implements Cloneable{ private int[] pole; public Stav(int[] pole){ this.pole = pole; } public Stav(Stav a){ this.pole = a.pole; } public void move(boolean left){ int empty = findEmpty(); if(left){ …
Lizardor
  • 15
  • 7
0
votes
2 answers

Implementing Cloneable and declaring CloneNotSupportedException but still getting CloneNotSupportedException

I'm making a program that constructs a set that takes in a variety of objects. However, when I try to clone the set I'm getting CloneNotSupportedException, despite declaring CloneNotSupportedException and implementing the Cloneable interface.…
Dio
  • 1
  • 3
0
votes
1 answer

Printing Results of clone() Method

Please Note: I created a post earlier that had this question along with several others, but was told that since I was asking so many questions in the same post, it'd be better to break it up into individual questions. So please do not mark this as a…
user2932587
0
votes
1 answer

Java desktop application peformance drop with "clone()"

Im making a 3D OpenGL LWJGL game and i've replaced a class for 3D float vectors with its generic version, and implemented "clone()" method from "Cloneable". After that, performance drops significally (GC usage went from below 1% to 10%). Here's a…
user2340939
  • 1,791
  • 2
  • 17
  • 44
0
votes
1 answer

Clarity needed on cloning: Shallow copying of objects is NOT just assigning object reference variable to another variable or is it?

I asked a question about cloning in java and got answers saying deep copy creates a new instance of the object carrying the same state and data in the member variables. I was told shallow copying is just assigning an object reference to another…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
0
votes
2 answers

Understanding what happens when we override the clone method with and without invoking super.clone?

I'm reading Effective Java by Joshua Bloch. I must say its a dense and complex book. The chapter on Methods Common to all objects (chapter 3) is proving hard for me to grasp as I've been programming for less than 3 years (1 year in java). I don't…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
0
votes
3 answers

Implementing a Deck of Cards in Java

So I have a lab (we are allowed to seek outside help on it, so here I am after lots of head scratching) where we have to implement a deck of cards. We have to use the enum class to create num For Suits: public enum Suits { CLUBS, HEARTS, DIAMONDS,…
0
votes
1 answer

Cloning a timepicker and datepicker

After reading all the subjects about it, I couldn't find my solution. I have a datepicker and 2 timepickers fields that I would like to clone. Those are to declare an intervention (date, start time, end time) that can last several days. I don't want…
El Manu
  • 61
  • 1
  • 1
  • 9
1 2 3
10
11