class.html

来自「API資料大全」· HTML 代码 · 共 1,325 行 · 第 1/5 页

HTML
1,325
字号
<DD><DL><DT><B>Parameters:</B><DD><CODE>className</CODE> - the fully qualified name of the desired class.<DT><B>Returns:</B><DD>the <code>Class</code> object for the class with the             specified name.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/LinkageError.html">LinkageError</A></CODE> - if the linkage fails<DD><CODE><A HREF="../../java/lang/ExceptionInInitializerError.html">ExceptionInInitializerError</A></CODE> - if the initialization provoked            by this method fails<DD><CODE><A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></CODE> - if the class cannot be located</DL></DD></DL><HR><A NAME="forName(java.lang.String, boolean, java.lang.ClassLoader)"><!-- --></A><H3>forName</H3><PRE>public static <A HREF="../../java/lang/Class.html">Class</A> <B>forName</B>(<A HREF="../../java/lang/String.html">String</A>&nbsp;name,                            boolean&nbsp;initialize,                            <A HREF="../../java/lang/ClassLoader.html">ClassLoader</A>&nbsp;loader)                     throws <A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></PRE><DL><DD>Returns the <code>Class</code> object associated with the class or interface with the given string name, using the given class loader. Given the fully qualified name for a class or interface (in the same format returned by <code>getName</code>) this method attempts to locate, load, and link the class or interface.  The specified class loader is used to load the class or interface.  If the parameter <code>loader</code> is null, the class is loaded through the bootstrap class loader.  The class is initialized only if the <code>initialize</code> parameter is <code>true</code> and if it has not been initialized earlier. <p> If <code>name</code> denotes a primitive type or void, an attempt will be made to locate a user-defined class in the unnamed package whose name is <code>name</code>. Therefore, this method cannot be used to obtain any of the <code>Class</code> objects representing primitive types or void. <p> If <code>name</code> denotes an array class, the component type of the array class is loaded but not initialized. <p> For example, in an instance method the expression: <blockquote><pre>  Class.forName("Foo") </pre></blockquote> is equivalent to: <blockquote><pre>  Class.forName("Foo", true, this.getClass().getClassLoader()) </pre></blockquote> Note that this method throws errors related to loading, linking or initializing as specified in Sections 12.2, 12.3 and 12.4 of <em>The Java Language Specification</em>. <p> If the <code>loader</code> is <code>null</code>, and a security manager is present, and the caller's class loader is not null, then this method calls the security manager's <code>checkPermission</code> method with a <code>RuntimePermission("getClassLoader")</code> permission to ensure it's ok to access the bootstrap class loader.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>name</CODE> - fully qualified name of the desired class<DD><CODE>initialize</CODE> - whether the class must be initialized<DD><CODE>loader</CODE> - class loader from which the class must be loaded<DT><B>Returns:</B><DD>class object representing the desired class<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/LinkageError.html">LinkageError</A></CODE> - if the linkage fails<DD><CODE><A HREF="../../java/lang/ExceptionInInitializerError.html">ExceptionInInitializerError</A></CODE> - if the initialization provoked            by this method fails<DD><CODE><A HREF="../../java/lang/ClassNotFoundException.html">ClassNotFoundException</A></CODE> - if the class cannot be located by            the specified class loader<DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/Class.html#forName(java.lang.String)"><CODE>forName(String)</CODE></A>, <A HREF="../../java/lang/ClassLoader.html"><CODE>ClassLoader</CODE></A></DL></DD></DL><HR><A NAME="newInstance()"><!-- --></A><H3>newInstance</H3><PRE>public <A HREF="../../java/lang/Object.html">Object</A> <B>newInstance</B>()                   throws <A HREF="../../java/lang/InstantiationException.html">InstantiationException</A>,                          <A HREF="../../java/lang/IllegalAccessException.html">IllegalAccessException</A></PRE><DL><DD>Creates a new instance of the class represented by this <tt>Class</tt> object.  The class is instantiatied as if by a <code>new</code> expression with an empty argument list.  The class is initialized if it has not already been initialized. <p>If there is a security manager, this method first calls the security manager's <code>checkMemberAccess</code> method with <code>this</code> and <code>Member.PUBLIC</code> as its arguments. If the class is in a package, then this method also calls the security manager's <code>checkPackageAccess</code> method with the package name as its argument. Either of these calls could result in a SecurityException.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>a newly allocated instance of the class represented by this             object.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/IllegalAccessException.html">IllegalAccessException</A></CODE> - if the class or initializer is               not accessible.<DD><CODE><A HREF="../../java/lang/InstantiationException.html">InstantiationException</A></CODE> - if this <code>Class</code> represents an abstract class,               an interface, an array class,               a primitive type, or void;               or if the instantiation fails for some other reason.<DD><CODE><A HREF="../../java/lang/ExceptionInInitializerError.html">ExceptionInInitializerError</A></CODE> - if the initialization               provoked by this method fails.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if there is no permission to create a new               instance.</DL></DD></DL><HR><A NAME="isInstance(java.lang.Object)"><!-- --></A><H3>isInstance</H3><PRE>public boolean <B>isInstance</B>(<A HREF="../../java/lang/Object.html">Object</A>&nbsp;obj)</PRE><DL><DD>Determines if the specified <code>Object</code> is assignment-compatible with the object represented by this <code>Class</code>.  This method is the dynamic equivalent of the Java language <code>instanceof</code> operator. The method returns <code>true</code> if the specified <code>Object</code> argument is non-null and can be cast to the reference type represented by this <code>Class</code> object without raising a <code>ClassCastException.</code> It returns <code>false</code> otherwise. <p> Specifically, if this <code>Class</code> object represents a declared class, this method returns <code>true</code> if the specified <code>Object</code> argument is an instance of the represented class (or of any of its subclasses); it returns <code>false</code> otherwise. If this <code>Class</code> object represents an array class, this method returns <code>true</code> if the specified <code>Object</code> argument can be converted to an object of the array class by an identity conversion or by a widening reference conversion; it returns <code>false</code> otherwise. If this <code>Class</code> object represents an interface, this method returns <code>true</code> if the class or any superclass of the specified <code>Object</code> argument implements this interface; it returns <code>false</code> otherwise. If this <code>Class</code> object represents a primitive type, this method returns <code>false</code>.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>obj</CODE> - the object to check<DT><B>Returns:</B><DD>true if <code>obj</code> is an instance of this class<DT><B>Since: </B><DD>JDK1.1</DD></DL></DD></DL><HR><A NAME="isAssignableFrom(java.lang.Class)"><!-- --></A><H3>isAssignableFrom</H3><PRE>public boolean <B>isAssignableFrom</B>(<A HREF="../../java/lang/Class.html">Class</A>&nbsp;cls)</PRE><DL><DD>Determines if the class or interface represented by this <code>Class</code> object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified <code>Class</code> parameter. It returns <code>true</code> if so; otherwise it returns <code>false</code>. If this <code>Class</code> object represents a primitive type, this method returns <code>true</code> if the specified <code>Class</code> parameter is exactly this <code>Class</code> object; otherwise it returns <code>false</code>. <p> Specifically, this method tests whether the type represented by the specified <code>Class</code> parameter can be converted to the type represented by this <code>Class</code> object via an identity conversion or via a widening reference conversion. See <em>The Java Language Specification</em>, sections 5.1.1 and 5.1.4 , for details.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>cls</CODE> - the <code>Class</code> object to be checked<DT><B>Returns:</B><DD>the <code>boolean</code> value indicating whether objects of the type <code>cls</code> can be assigned to objects of this class<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if the specified Class parameter is            null.<DT><B>Since: </B><DD>JDK1.1</DD></DL></DD></DL><HR><A NAME="isInterface()"><!-- --></A><H3>isInterface</H3><PRE>public boolean <B>isInterface</B>()</PRE><DL><DD>Determines if the specified <code>Class</code> object represents an interface type.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD><code>true</code> if this object represents an interface;          <code>false</code> otherwise.</DL></DD></DL><HR><A NAME="isArray()"><!-- --></A><H3>isArray</H3><PRE>public boolean <B>isArray</B>()</PRE><DL><DD>Determines if this <code>Class</code> object represents an array class.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD><code>true</code> if this object represents an array class;          <code>false</code> otherwise.<DT><B>Since: </B><DD>JDK1.1</DD></DL></DD></DL><HR><A NAME="isPrimitive()"><!-- --></A><H3>isPrimitive</H3><PRE>public boolean <B>isPrimitive</B>()</PRE><DL><DD>Determines if the specified <code>Class</code> object represents a primitive type. <p> There are nine predefined <code>Class</code> objects to represent the eight primitive types and void.  These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely <code>boolean</code>, <code>byte</code>, <code>char</code>, <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code>, and <code>double</code>. <p> These objects may only be accessed via the following public static final variables, and are the only <code>Class</code> objects for which this method returns <code>true</code>.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>true if and only if this class represents a primitive type<DT><B>Since: </B><DD>JDK1.1</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/Boolean.html#TYPE"><CODE>Boolean.TYPE</CODE></A>, <A HREF="../../java/lang/Character.html#TYPE"><CODE>Character.TYPE</CODE></A>, <A HREF="../../java/lang/Byte.html#TYPE"><CODE>Byte.TYPE</CODE></A>, <A HREF="../../java/lang/Short.html#TYPE"><CODE>Short.TYPE</CODE></A>, <A HREF="../../java/lang/Integer.html#TYPE"><CODE>Integer.TYPE</CODE></A>, <A HREF="../../java/lang/Long.html#TYPE"><CODE>Long.TYPE</CODE></A>, <A HREF="../../java/lang/Float.html#TYPE"><CODE>Float.TYPE</CODE></A>, <A HREF="../../java/lang/Double.html#TYPE"><CODE>Double.TYPE</CODE></A>, <A HREF="../../java/lang/Void.html#TYPE"><CODE>Void.TYPE</CODE></A></DL></DD></DL><HR><A NAME="getName()"><!-- --></A><H3>getName</H3><PRE>public <A HREF="../../java/lang/String.html">String</A> <B>getName</B>()</PRE><DL><DD>Returns the fully-qualified name of the entity (class, interface, array class, primitive type, or void) represented by this <code>Class</code> object, as a <code>String</code>. <p> If this <code>Class</code> object represents a class of arrays, then the internal form of the name consists of the name of the element type in Java signature format, preceded by one or more "<tt>[</tt>" characters representing the depth of array nesting. Thus: <blockquote><pre> (new Object[3]).getClass().getName() </pre></blockquote> returns "<code>[Ljava.lang.Object;</code>" and: <blockquote><pre> (new int[3][4][5][6][7][8][9]).getClass().getName() </pre></blockquote> returns "<code>[[[[[[[I</code>". The encoding of element type names  is as follows: <blockquote><pre>

⌨️ 快捷键说明

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