Enum and Cloning

What is enum and cloning for? i seen the urls at java
but still do not understand..
please do give examples thanks.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi jedistar,

clones are deep copies, completely new object but exactly like the first.  There is something your probably more familer with, a shallow copy, here are the differences.

Shallow Copy: (Just a reference)
Integer i = new Integer(10);
Integer j = i;
// Now any change to i also changes j (as long as i does not make a new reference)

Deep Copy (simulated, this is pretty much what clone does):
Integer i = new Integer(10);
Integer j = new Integer(i.intValue());
// Now any change to i has no affect on j

I am not too certain on enums.  They are just objects, inside an object. =)
Joe P

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Manikandan ThiagarajanSenior consultantCommented:
jedistarAuthor Commented:
nice, how do u use cloning, samples?
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

If you follow stmani's link it had a nice suggestion.
One was to make a clone of an object as a backup.
Do stuff to the original object to see what happens (maybe compare the clone and original now), then when you want to "rollback" you would just go back to the clone that you made.  Or similarly just make all changes to the clone and compare it to the unchanged original.

Joe P
jedistarAuthor Commented:
Do need a sample code to understand this thanks.
Here is some direct code:

Did you want an application?
jedistarAuthor Commented:
jus some sample codes will do
jedistarAuthor Commented:
ahh don't really understand that url code
I'll try to add some comments.

// Notice that this implements clonable, therefore it should write the
// clone() method, it must return an object.
    class MyClass implements Cloneable {
        // Just a simple constructor
        public MyClass() {

        //  Once again the goal of a clone() method
        // is to make a COPY of the current object.  So
        // If there were class variables you set all of them
        // for the new variable (in this case theClone)
        public Object clone() {
            Cloneable theClone = new MyClass();
            // Initialize theClone.
            return theClone;

// Here's one object myObject, we create it  
MyClass myObject = new MyClass();
// This new object myObjectClone is a clone of myObject
// it will be exactly the same as the above, but any change
// to one will NOT affect the other
MyClass myObjectClone = (MyClass)myObject.clone();

Arrays are automatically cloneable:
// This is a practical example, arrays can always be cloned
int[] ints = new int[]{123, 234};
int[] intsClone = (int[])ints.clone();

Joe P
jedistarAuthor Commented:
is this shallow or deep cloning
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.