Java Enum.clone()

Syntax

Enum.clone() has the following syntax.

protected final Object clone()   throws CloneNotSupportedException

Example

In the following code shows how to use Enum.clone() method.


//ww  w.  java  2  s. c om
enum Tutorial {
   CSS(400), HTML(250);
  
   int price;
   Tutorial(int p) {
      price = p;
   }
   int showPrice() {
      return price;
   } 
}

public class Main {

   public static void main(String args[]) {

      Main t = new Main() {
         protected final Object clone() throws CloneNotSupportedException {
            throw new CloneNotSupportedException();
         }
      }; 

      for(Tutorial m : Tutorial.values()) {
         System.out.println(m + " costs " + m.showPrice() + " dollars");
      }                    
   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable