📄 class.java
字号:
public native Field getDeclaredField(String fieldName) throws NoSuchFieldException; /** * Get all the declared fields in this class, but not those inherited from * superclasses. This returns an array of length 0 if there are no fields, * including for primitive types. This does not return the implicit length * field of arrays. A security check may be performed, with * <code>checkMemberAccess(this, Member.DECLARED)</code> as well as * <code>checkPackageAccess</code> both having to succeed. * * @return all declared fields in this class * @throws SecurityException if the security check fails * @since 1.1 */ public Field[] getDeclaredFields() { memberAccessCheck(Member.DECLARED); return getDeclaredFields(false); } native Field[] getDeclaredFields (boolean publicOnly); private native Method _getDeclaredMethod(String methodName, Class[] args); /** * Get a method declared in this class, where name is its simple name. The * implicit methods of Object are not available from arrays or interfaces. * Constructors (named "<init>" in the class file) and class initializers * (name "<clinit>") are not available. The Virtual Machine allows * multiple methods with the same signature but differing return types; in * such a case the most specific return types are favored, then the final * choice is arbitrary. If the method takes no argument, an array of zero * elements and null are equivalent for the types argument. A security * check may be performed, with * <code>checkMemberAccess(this, Member.DECLARED)</code> as well as * <code>checkPackageAccess</code> both having to succeed. * * @param methodName the name of the method * @param types the type of each parameter * @return the method * @throws NoSuchMethodException if the method does not exist * @throws SecurityException if the security check fails * @see #getDeclaredMethods() * @since 1.1 */ public Method getDeclaredMethod(String methodName, Class[] args) throws NoSuchMethodException { memberAccessCheck(Member.DECLARED); if ("<init>".equals(methodName) || "<clinit>".equals(methodName)) throw new NoSuchMethodException(methodName); Method match = _getDeclaredMethod(methodName, args); if (match == null) throw new NoSuchMethodException(methodName); return match; } /** * Get all the declared methods in this class, but not those inherited from * superclasses. This returns an array of length 0 if there are no methods, * including for primitive types. This does include the implicit methods of * arrays and interfaces which mirror methods of Object, nor does it * include constructors or the class initialization methods. The Virtual * Machine allows multiple methods with the same signature but differing * return types; all such methods are in the returned array. A security * check may be performed, with * <code>checkMemberAccess(this, Member.DECLARED)</code> as well as * <code>checkPackageAccess</code> both having to succeed. * * @return all declared methods in this class * @throws SecurityException if the security check fails * @since 1.1 */ public native Method[] getDeclaredMethods(); /** * If this is a nested or inner class, return the class that declared it. * If not, return null. * * @return the declaring class of this class * @since 1.1 */ // This is marked as unimplemented in the JCL book. public native Class getDeclaringClass (); private native Field getField (String fieldName, int hash) throws NoSuchFieldException; /** * Get a public field declared or inherited in this class, where name is * its simple name. If the class contains multiple accessible fields by * that name, an arbitrary one is returned. The implicit length field of * arrays is not available. A security check may be performed, with * <code>checkMemberAccess(this, Member.PUBLIC)</code> as well as * <code>checkPackageAccess</code> both having to succeed. * * @param fieldName the name of the field * @return the field * @throws NoSuchFieldException if the field does not exist * @throws SecurityException if the security check fails * @see #getFields() * @since 1.1 */ public Field getField(String fieldName) throws NoSuchFieldException { memberAccessCheck(Member.PUBLIC); Field field = getField(fieldName, fieldName.hashCode()); if (field == null) throw new NoSuchFieldException(fieldName); return field; } /** * Get all the public fields declared in this class or inherited from * superclasses. This returns an array of length 0 if there are no fields, * including for primitive types. This does not return the implicit length * field of arrays. A security check may be performed, with * <code>checkMemberAccess(this, Member.PUBLIC)</code> as well as * <code>checkPackageAccess</code> both having to succeed. * * @return all public fields in this class * @throws SecurityException if the security check fails * @since 1.1 */ public Field[] getFields() { memberAccessCheck(Member.PUBLIC); return internalGetFields(); } /** * Like <code>getFields()</code> but without the security checks. */ private Field[] internalGetFields() { HashSet set = new HashSet(); set.addAll(Arrays.asList(getDeclaredFields(true))); Class[] interfaces = getInterfaces(); for (int i = 0; i < interfaces.length; i++) set.addAll(Arrays.asList(interfaces[i].internalGetFields())); Class superClass = getSuperclass(); if (superClass != null) set.addAll(Arrays.asList(superClass.internalGetFields())); return (Field[])set.toArray(new Field[set.size()]); } /** * Returns the <code>Package</code> in which this class is defined * Returns null when this information is not available from the * classloader of this class. * * @return the package for this class, if it is available * @since 1.2 */ public Package getPackage() { ClassLoader cl = getClassLoader(); if (cl != null) return cl.getPackage(getPackagePortion(getName())); else return VMClassLoader.getPackage(getPackagePortion(getName())); } /** * Get the interfaces this class <em>directly</em> implements, in the * order that they were declared. This returns an empty array, not null, * for Object, primitives, void, and classes or interfaces with no direct * superinterface. Array types return Cloneable and Serializable. * * @return the interfaces this class directly implements */ public native Class[] getInterfaces (); private final native void getSignature(StringBuffer buffer); private static final native String getSignature(Class[] args, boolean is_construtor); public native Method _getMethod(String methodName, Class[] args); /** * Get a public method declared or inherited in this class, where name is * its simple name. The implicit methods of Object are not available from * interfaces. Constructors (named "<init>" in the class file) and class * initializers (name "<clinit>") are not available. The Virtual * Machine allows multiple methods with the same signature but differing * return types, and the class can inherit multiple methods of the same * return type; in such a case the most specific return types are favored, * then the final choice is arbitrary. If the method takes no argument, an * array of zero elements and null are equivalent for the types argument. * A security check may be performed, with * <code>checkMemberAccess(this, Member.PUBLIC)</code> as well as * <code>checkPackageAccess</code> both having to succeed. * * @param methodName the name of the method * @param types the type of each parameter * @return the method * @throws NoSuchMethodException if the method does not exist * @throws SecurityException if the security check fails * @see #getMethods() * @since 1.1 */ public Method getMethod(String methodName, Class[] args) throws NoSuchMethodException { memberAccessCheck(Member.PUBLIC); if ("<init>".equals(methodName) || "<clinit>".equals(methodName)) throw new NoSuchMethodException(methodName); Method method = _getMethod(methodName, args); if (method == null) throw new NoSuchMethodException(methodName); return method; } private native int _getMethods (Method[] result, int offset); /** * Get all the public methods declared in this class or inherited from * superclasses. This returns an array of length 0 if there are no methods, * including for primitive types. This does not include the implicit * methods of interfaces which mirror methods of Object, nor does it * include constructors or the class initialization methods. The Virtual * Machine allows multiple methods with the same signature but differing * return types; all such methods are in the returned array. A security * check may be performed, with * <code>checkMemberAccess(this, Member.PUBLIC)</code> as well as * <code>checkPackageAccess</code> both having to succeed. * * @return all public methods in this class * @throws SecurityException if the security check fails * @since 1.1 */ public native Method[] getMethods(); /** * Get the modifiers of this class. These can be decoded using Modifier, * and is limited to one of public, protected, or private, and any of * final, static, abstract, or interface. An array class has the same * public, protected, or private modifier as its component type, and is * marked final but not an interface. Primitive types and void are marked * public and final, but not an interface. * * @return the modifiers of this class * @see Modifer * @since 1.1 */ public native int getModifiers (); /** * Get the name of this class, separated by dots for package separators. * If the class represents a primitive type, or void, then the * name of the type as it appears in the Java programming language * is returned. For instance, <code>Byte.TYPE.getName()</code> * returns "byte". * * Arrays are specially encoded as shown on this table. * <pre> * array type [<em>element type</em> * (note that the element type is encoded per * this table) * boolean Z * byte B * char C * short S * int I * long J * float F * double D * void V * class or interface, alone: <dotted name> * class or interface, as element type: L<dotted name>; * </pre> * * @return the name of this class */ public native String getName (); /** * Get a resource URL using this class's package using the * getClassLoader().getResource() method. If this class was loaded using * the system classloader, ClassLoader.getSystemResource() is used instead. * * <p>If the name you supply is absolute (it starts with a <code>/</code>), * then the leading <code>/</code> is removed and it is passed on to * getResource(). If it is relative, the package name is prepended, and * <code>.</code>'s are replaced with <code>/</code>. * * <p>The URL returned is system- and classloader-dependent, and could * change across implementations. * * @param resourceName the name of the resource, generally a path * @return the URL to the resource * @throws NullPointerException if name is null * @since 1.1 */ public URL getResource(String resourceName) { String name = resourcePath(resourceName); ClassLoader loader = getClassLoader();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -