/[classpath]/classpath/java/lang/Class.java
ViewVC logotype

Diff of /classpath/java/lang/Class.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.22.2.5 by gnu_andrew, Fri Jan 7 03:42:30 2005 UTC revision 1.22.2.6 by gnu_andrew, Mon Jan 10 18:25:47 2005 UTC
# Line 1  Line 1 
1  /* Class.java -- Representation of a Java class.  /* Class.java -- Representation of a Java class.
2     Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004     Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005
3     Free Software Foundation     Free Software Foundation
4    
5  This file is part of GNU Classpath.  This file is part of GNU Classpath.
# Line 83  import java.util.HashSet; Line 83  import java.util.HashSet;
83   * @author John Keiser   * @author John Keiser
84   * @author Eric Blake (ebb9@email.byu.edu)   * @author Eric Blake (ebb9@email.byu.edu)
85   * @author Tom Tromey (tromey@redhat.com)   * @author Tom Tromey (tromey@redhat.com)
86     * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
87   * @since 1.0   * @since 1.0
88   * @see ClassLoader   * @see ClassLoader
89   */   */
90  public final class Class<K> implements Serializable  public final class Class<T> implements Serializable
91  {  {
92    /**    /**
93     * Compatible with JDK 1.0+.     * Compatible with JDK 1.0+.
# Line 308  public final class Class<K> implements S Line 309  public final class Class<K> implements S
309     * @see #getConstructors()     * @see #getConstructors()
310     * @since 1.1     * @since 1.1
311     */     */
312    public Constructor<K> getConstructor(Class... types)    public Constructor<T> getConstructor(Class... types)
313      throws NoSuchMethodException      throws NoSuchMethodException
314    {    {
315      memberAccessCheck(Member.PUBLIC);      memberAccessCheck(Member.PUBLIC);
# Line 354  public final class Class<K> implements S Line 355  public final class Class<K> implements S
355     * @see #getDeclaredConstructors()     * @see #getDeclaredConstructors()
356     * @since 1.1     * @since 1.1
357     */     */
358    public Constructor<K> getDeclaredConstructor(Class... types)    public Constructor<T> getDeclaredConstructor(Class... types)
359      throws NoSuchMethodException      throws NoSuchMethodException
360    {    {
361      memberAccessCheck(Member.DECLARED);      memberAccessCheck(Member.DECLARED);
# Line 1261  public final class Class<K> implements S Line 1262  public final class Class<K> implements S
1262     * @throws ClassCastException  if obj is not an instance of this class     * @throws ClassCastException  if obj is not an instance of this class
1263     * @since 1.5     * @since 1.5
1264     */     */
1265    public K cast(Object obj)    public T cast(Object obj)
1266    {    {
1267      return VMClass.cast(obj, this);      return VMClass.cast(obj, this);
1268    }    }
# Line 1321  public final class Class<K> implements S Line 1322  public final class Class<K> implements S
1322            sm.checkPackageAccess(pkg.getName());            sm.checkPackageAccess(pkg.getName());
1323        }        }
1324    }    }
1325    
1326      /**
1327       * Returns the enumeration constants of this class, or
1328       * null if this class is not an <code>Enum</code>.
1329       *
1330       * @return an array of <code>Enum</code> constants
1331       *         associated with this class, or null if this
1332       *         class is not an <code>enum</code>.
1333       */
1334      public T[] getEnumConstants()
1335      {
1336        if (isEnum())
1337          {
1338            try
1339              {
1340                return (T[])
1341                  getMethod("values", null).invoke(null,null);
1342              }
1343            catch (NoSuchMethodException exception)
1344              {
1345                throw new Error("Enum lacks values() method");
1346              }
1347            catch (IllegalAccessException exception)
1348              {
1349                throw new Error("Unable to access Enum class");
1350              }
1351            catch (InvocationTargetException exception)
1352              {
1353                throw new
1354                  RuntimeException("The values method threw an exception",
1355                                   exception);
1356              }
1357          }
1358        else
1359          {
1360            return null;
1361          }
1362      }
1363    
1364      /**
1365       * Returns true if this class is an <code>Enum</code>.
1366       *
1367       * @return true if this is an enumeration class.
1368       */
1369      public boolean isEnum()
1370      {
1371        return getSuperclass() == Enum.class;
1372      }
1373    
1374  }  }

Legend:
Removed from v.1.22.2.5  
changed lines
  Added in v.1.22.2.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26