src/share/classes/com/sun/beans/editors/EnumEditor.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -43,21 +43,22 @@
  * @author Sergey A. Malenkov
  */
 public final class EnumEditor implements PropertyEditor {
     private final List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
 
-    private final Class type;
+    @SuppressWarnings("rawtypes")
+    private final Class<? extends Enum> type;
     private final String[] tags;
 
     private Object value;
 
-    public EnumEditor( Class type ) {
+    public EnumEditor(Class<?> type) {
         Object[] values = type.getEnumConstants();
         if ( values == null ) {
             throw new IllegalArgumentException( "Unsupported " + type );
         }
-        this.type = type;
+        this.type = type.asSubclass(java.lang.Enum.class);
         this.tags = new String[values.length];
         for ( int i = 0; i < values.length; i++ ) {
             this.tags[i] = ( ( Enum )values[i] ).name();
         }
     }

@@ -96,13 +97,15 @@
                 ? ( ( Enum )this.value ).name()
                 : null;
     }
 
     public void setAsText( String text ) {
-        setValue( ( text != null )
-                ? Enum.valueOf( this.type, text )
-                : null );
+        @SuppressWarnings("unchecked")
+        Object tmp = ( text != null )
+            ? Enum.valueOf( (Class)this.type, text )
+            : null;
+        setValue(tmp);
     }
 
     public String[] getTags() {
         return this.tags.clone();
     }