⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.java

📁 linux下编程用 编译软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   * <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);  }  Field[] getDeclaredFields (boolean publicOnly)  {    return VMClass.getDeclaredFields (this, publicOnly);  }  /**   * 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 "&lt;init&gt;" in the class file) and class initializers   * (name "&lt;clinit&gt;") 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[] types)    throws NoSuchMethodException  {    memberAccessCheck(Member.DECLARED);    Method match = matchMethod(getDeclaredMethods(false), methodName, types);    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 Method[] getDeclaredMethods()  {    memberAccessCheck(Member.DECLARED);    return getDeclaredMethods(false);  }  Method[] getDeclaredMethods (boolean publicOnly)  {    return VMClass.getDeclaredMethods (this, publicOnly);  }   /**   * 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   */  public Class getDeclaringClass()  {    return VMClass.getDeclaringClass (this);  }  /**   * 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 = internalGetField(fieldName);    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 or when the classloader of this class   * is null.   *   * @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 Class[] getInterfaces()  {    return VMClass.getInterfaces (this);  }  private static final class MethodKey  {    private String name;    private Class[] params;    private Class returnType;    private int hash;        MethodKey(Method m)    {      name = m.getName();      params = m.getParameterTypes();      returnType = m.getReturnType();      hash = name.hashCode() ^ returnType.hashCode();      for(int i = 0; i < params.length; i++)	{	  hash ^= params[i].hashCode();	}    }        public boolean equals(Object o)    {      if(o instanceof MethodKey)	{	  MethodKey m = (MethodKey)o;	  if(m.name.equals(name) && m.params.length == params.length && m.returnType == returnType)	    {	      for(int i = 0; i < params.length; i++)		{		  if(m.params[i] != params[i])		    {		      return false;		    }		}	      return true;	    }	}      return false;    }        public int hashCode()    {      return hash;    }  }    /**   * 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 "&lt;init&gt;" in the class file) and class   * initializers (name "&lt;clinit&gt;") 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[] types)    throws NoSuchMethodException  {    memberAccessCheck(Member.PUBLIC);    Method method = internalGetMethod(methodName, types);    if (method == null)      throw new NoSuchMethodException(methodName);    return method;  }  /**   * Like <code>getMethod(String,Class[])</code> but without the security   * checks and returns null instead of throwing NoSuchMethodException.   */  private Method internalGetMethod(String methodName, Class[] args)  {    Method match = matchMethod(getDeclaredMethods(true), methodName, args);    if (match != null)      return match;    Class superClass = getSuperclass();    if (superClass != null)      {	match = superClass.internalGetMethod(methodName, args);	if(match != null)	  return match;      }    Class[] interfaces = getInterfaces();    for (int i = 0; i < interfaces.length; i++)      {	match = interfaces[i].internalGetMethod(methodName, args);	if (match != null)	  return match;      }    return null;  }  /**    * Find the best matching method in <code>list</code> according to   * the definition of ``best matching'' used by <code>getMethod()</code>   *   * <p>   * Returns the method if any, otherwise <code>null</code>.   *   * @param list List of methods to search   * @param name Name of method   * @param args Method parameter types   * @see #getMethod(String, Class[])   */  private static Method matchMethod(Method[] list, String name, Class[] args)  {    Method match = null;    for (int i = 0; i < list.length; i++)      {	Method method = list[i];	if (!method.getName().equals(name))	  continue;	if (!matchParameters(args, method.getParameterTypes()))	  continue;	if (match == null	    || match.getReturnType().isAssignableFrom(method.getReturnType()))	  match = method;      }    return match;  }  /**   * Check for an exact match between parameter type lists.   * Either list may be <code>null</code> to mean a list of   * length zero.   */  private static boolean matchParameters(Class[] types1, Class[] types2)  {    if (types1 == null)      return types2 == null || types2.length == 0;    if (types2 == null)      return types1 == null || types1.length == 0;    if (types1.length != types2.length)      return false;    for (int i = 0; i < types1.length; i++)      {	if (types1[i] != types2[i])	  return false;      }    return true;  }    /**   * 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 Method[] getMethods()  {    memberAccessCheck(Member.PUBLIC);    // NOTE the API docs claim that no methods are returned for arrays,    // but Sun's implementation *does* return the public methods of Object    // (as would be expected), so we follow their implementation instead    // of their documentation.    return internalGetMethods();  }  /**   * Like <code>getMethods()</code> but without the security checks.   */  private Method[] internalGetMethods()  {    HashMap map = new HashMap();    Method[] methods;    Class[] interfaces = getInterfaces();    for(int i = 0; i < interfaces.length; i++)      {	methods = interfaces[i].internalGetMethods();	for(int j = 0; j < methods.length; j++)	  {	    map.put(new MethodKey(methods[j]), methods[j]);	  }      }    Class superClass = getSuperclass();    if(superClass != null)      {	methods = superClass.internalGetMethods();	for(int i = 0; i < methods.length; i++)	  {	    map.put(new MethodKey(methods[i]), methods[i]);	  }      }    methods = getDeclaredMethods(true);    for(int i = 0; i < methods.length; i++)      {	map.put(new MethodKey(methods[i]), methods[i]);      }    return (Method[])map.values().toArray(new Method[map.size()]);  }  /**   * 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 Modifier   * @since 1.1   */  public int getModifiers()  {    return VMClass.getModifiers (this, false);  }    /**   * 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: &lt;dotted name&gt;   * class or interface, as element type: L&lt;dotted name&gt;;   * </pre>   *   * @return the name of this class   */  public String getName()  {     return VMClass.getName (this);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -