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. |
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+. |
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); |
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); |
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 |
} |
} |
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 |
} |
} |