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

📄 class.java

📁 linux下编程用 编译软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  }  /**   * 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();    if (loader == null)      return ClassLoader.getSystemResource(name);    return loader.getResource(name);  }  /**   * Get a resource using this class's package using the   * getClassLoader().getResourceAsStream() 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 an InputStream with the contents of the resource in it, or null   * @throws NullPointerException if name is null   * @since 1.1   */  public InputStream getResourceAsStream(String resourceName)  {    String name = resourcePath(resourceName);    ClassLoader loader = getClassLoader();    if (loader == null)      return ClassLoader.getSystemResourceAsStream(name);    return loader.getResourceAsStream(name);  }  private String resourcePath(String resourceName)  {    if (resourceName.length() > 0)      {	if (resourceName.charAt(0) != '/')	  {	    String pkg = getPackagePortion(getName());	    if (pkg.length() > 0)	      resourceName = pkg.replace('.','/') + '/' + resourceName;	  }	else	  {	    resourceName = resourceName.substring(1);	  }      }    return resourceName;  }  /**   * Get the signers of this class. This returns null if there are no signers,   * such as for primitive types or void.   *   * @return the signers of this class   * @since 1.1   */  public Object[] getSigners()  {    return signers == null ? null : (Object[]) signers.clone ();  }    /**   * Set the signers of this class.   *   * @param signers the signers of this class   */  void setSigners(Object[] signers)  {    this.signers = signers;  }  /**   * Get the direct superclass of this class.  If this is an interface,   * Object, a primitive type, or void, it will return null. If this is an   * array type, it will return Object.   *   * @return the direct superclass of this class   */  public Class getSuperclass()  {    return VMClass.getSuperclass (this);  }    /**   * Return whether this class is an array type.   *   * @return whether this class is an array type   * @since 1.1   */  public boolean isArray()  {    return VMClass.isArray (this);  }    /**   * Discover whether an instance of the Class parameter would be an   * instance of this Class as well.  Think of doing   * <code>isInstance(c.newInstance())</code> or even   * <code>c.newInstance() instanceof (this class)</code>. While this   * checks widening conversions for objects, it must be exact for primitive   * types.   *   * @param c the class to check   * @return whether an instance of c would be an instance of this class   *         as well   * @throws NullPointerException if c is null   * @since 1.1   */  public boolean isAssignableFrom(Class c)  {    return VMClass.isAssignableFrom (this, c);  }   /**   * Discover whether an Object is an instance of this Class.  Think of it   * as almost like <code>o instanceof (this class)</code>.   *   * @param o the Object to check   * @return whether o is an instance of this class   * @since 1.1   */  public boolean isInstance(Object o)  {    return VMClass.isInstance (this, o);  }    /**   * Check whether this class is an interface or not.  Array types are not   * interfaces.   *   * @return whether this class is an interface or not   */  public boolean isInterface()  {    return VMClass.isInterface (this);  }    /**   * Return whether this class is a primitive type.  A primitive type class   * is a class representing a kind of "placeholder" for the various   * primitive types, or void.  You can access the various primitive type   * classes through java.lang.Boolean.TYPE, java.lang.Integer.TYPE, etc.,   * or through boolean.class, int.class, etc.   *   * @return whether this class is a primitive type   * @see Boolean#TYPE   * @see Byte#TYPE   * @see Character#TYPE   * @see Short#TYPE   * @see Integer#TYPE   * @see Long#TYPE   * @see Float#TYPE   * @see Double#TYPE   * @see Void#TYPE   * @since 1.1   */  public boolean isPrimitive()  {    return VMClass.isPrimitive (this);  }    /**   * Get a new instance of this class by calling the no-argument constructor.   * The class is initialized if it has not been already. A security check   * may be performed, with <code>checkMemberAccess(this, Member.PUBLIC)</code>   * as well as <code>checkPackageAccess</code> both having to succeed.   *   * @return a new instance of this class   * @throws InstantiationException if there is not a no-arg constructor   *         for this class, including interfaces, abstract classes, arrays,   *         primitive types, and void; or if an exception occurred during   *         the constructor   * @throws IllegalAccessException if you are not allowed to access the   *         no-arg constructor because of scoping reasons   * @throws SecurityException if the security check fails   * @throws ExceptionInInitializerError if class initialization caused by   *         this call fails with an exception   */  public Object newInstance()    throws InstantiationException, IllegalAccessException  {    memberAccessCheck(Member.PUBLIC);    Constructor constructor;    synchronized(this)      {	constructor = this.constructor;      }    if (constructor == null)      {	Constructor[] constructors = getDeclaredConstructors(false);	for (int i = 0; i < constructors.length; i++)	  {	    if (constructors[i].getParameterTypes().length == 0)	      {		constructor = constructors[i];		break;	      }	  }	if (constructor == null)	  throw new InstantiationException(getName());	if (!Modifier.isPublic(constructor.getModifiers())            || !Modifier.isPublic(VMClass.getModifiers(this, true)))	  {	    final Constructor finalConstructor = constructor;	    AccessController.doPrivileged(new PrivilegedAction()	      {		public Object run()	        {		  finalConstructor.setAccessible(true);		  return null;		}	      });	  }	synchronized(this)	  {	    if (this.constructor == null)	      this.constructor = constructor;	  }	          }    int modifiers = constructor.getModifiers();    if (!Modifier.isPublic(modifiers)        || !Modifier.isPublic(VMClass.getModifiers(this, true)))      {	Class caller = VMStackWalker.getCallingClass();	if (caller != null &&	    caller != this &&	    (Modifier.isPrivate(modifiers)	     || getClassLoader() != caller.getClassLoader()	     || !getPackagePortion(getName())	     .equals(getPackagePortion(caller.getName()))))	  throw new IllegalAccessException(getName()					   + " has an inaccessible constructor");      }    try      {        return constructor.newInstance(null);      }    catch (InvocationTargetException e)      {	VMClass.throwException(e.getTargetException());	throw (InternalError) new InternalError	  ("VMClass.throwException returned").initCause(e);      }  }  /**   * Returns the protection domain of this class. If the classloader did not   * record the protection domain when creating this class the unknown   * protection domain is returned which has a <code>null</code> code source   * and all permissions. A security check may be performed, with   * <code>RuntimePermission("getProtectionDomain")</code>.   *   * @return the protection domain   * @throws SecurityException if the security manager exists and the caller   * does not have <code>RuntimePermission("getProtectionDomain")</code>.   * @see RuntimePermission   * @since 1.2   */  public ProtectionDomain getProtectionDomain()  {    SecurityManager sm = SecurityManager.current;    if (sm != null)      sm.checkPermission(new RuntimePermission("getProtectionDomain"));    return pd == null ? StaticData.unknownProtectionDomain : pd;  }  /**   * Return the human-readable form of this Object.  For an object, this   * is either "interface " or "class " followed by <code>getName()</code>,   * for primitive types and void it is just <code>getName()</code>.   *   * @return the human-readable form of this Object   */  public String toString()  {    if (isPrimitive())      return getName();    return (isInterface() ? "interface " : "class ") + getName();  }  /**   * Returns the desired assertion status of this class, if it were to be   * initialized at this moment. The class assertion status, if set, is   * returned; the backup is the default package status; then if there is   * a class loader, that default is returned; and finally the system default   * is returned. This method seldom needs calling in user code, but exists   * for compilers to implement the assert statement. Note that there is no   * guarantee that the result of this method matches the class's actual   * assertion status.   *   * @return the desired assertion status   * @see ClassLoader#setClassAssertionStatus(String, boolean)   * @see ClassLoader#setPackageAssertionStatus(String, boolean)   * @see ClassLoader#setDefaultAssertionStatus(boolean)   * @since 1.4   */  public boolean desiredAssertionStatus()  {    ClassLoader c = getClassLoader();    Object status;    if (c == null)      return VMClassLoader.defaultAssertionStatus();    if (c.classAssertionStatus != null)      synchronized (c)        {          status = c.classAssertionStatus.get(getName());          if (status != null)            return status.equals(Boolean.TRUE);        }    else      {        status = ClassLoader.StaticData.                    systemClassAssertionStatus.get(getName());        if (status != null)          return status.equals(Boolean.TRUE);      }    if (c.packageAssertionStatus != null)      synchronized (c)        {          String name = getPackagePortion(getName());          if ("".equals(name))            status = c.packageAssertionStatus.get(null);          else            do              {                status = c.packageAssertionStatus.get(name);                name = getPackagePortion(name);              }            while (! "".equals(name) && status == null);          if (status != null)            return status.equals(Boolean.TRUE);        }    else      {        String name = getPackagePortion(getName());        if ("".equals(name))          status = ClassLoader.StaticData.                    systemPackageAssertionStatus.get(null);        else          do            {              status = ClassLoader.StaticData.                        systemPackageAssertionStatus.get(name);              name = getPackagePortion(name);            }          while (! "".equals(name) && status == null);        if (status != null)          return status.equals(Boolean.TRUE);      }    return c.defaultAssertionStatus;  }  /**   * Like <code>getField(String)</code> but without the security checks and returns null   * instead of throwing NoSuchFieldException.   */  private Field internalGetField(String name)  {    Field[] fields = getDeclaredFields(true);    for (int i = 0; i < fields.length; i++)      {	Field field = fields[i];	if (field.getName().equals(name))	  return field;      }    Class[] interfaces = getInterfaces();    for (int i = 0; i < interfaces.length; i++)      {	Field field = interfaces[i].internalGetField(name);	if(field != null)	  return field;      }    Class superClass = getSuperclass();    if (superClass != null)      return superClass.internalGetField(name);    return null;  }  /**   * Strip the last portion of the name (after the last dot).   *   * @param name the name to get package of   * @return the package name, or "" if no package   */  private static String getPackagePortion(String name)  {    int lastInd = name.lastIndexOf('.');    if (lastInd == -1)      return "";    return name.substring(0, lastInd);  }  /**   * Perform security checks common to all of the methods that   * get members of this Class.   */  private void memberAccessCheck(int which)  {    SecurityManager sm = SecurityManager.current;    if (sm != null)      {	sm.checkMemberAccess(this, which);	Package pkg = getPackage();	if (pkg != null)	  sm.checkPackageAccess(pkg.getName());      }  }}

⌨️ 快捷键说明

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