/[classpath]/classpath/java/lang/Class.java
ViewVC logotype

Diff of /classpath/java/lang/Class.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.22 by jfrijters, Tue Jul 27 07:28:01 2004 UTC revision 1.22.2.1 by tromey, Sat Aug 7 00:27:06 2004 UTC
# Line 86  import java.util.HashSet; Line 86  import java.util.HashSet;
86   * @since 1.0   * @since 1.0
87   * @see ClassLoader   * @see ClassLoader
88   */   */
89  public final class Class implements Serializable  public final class Class<K> implements Serializable
90  {  {
91    /**    /**
92     * Compatible with JDK 1.0+.     * Compatible with JDK 1.0+.
# Line 144  public final class Class implements Seri Line 144  public final class Class implements Seri
144     * @throws ExceptionInInitializerError if the class loads, but an exception     * @throws ExceptionInInitializerError if the class loads, but an exception
145     *         occurs during initialization     *         occurs during initialization
146     */     */
147    public static Class forName(String name) throws ClassNotFoundException    public static Class<?> forName(String name) throws ClassNotFoundException
148    {    {
149      Class result = VMClass.forName (name);      Class<?> result = VMClass.forName (name);
150      if (result == null)      if (result == null)
151        result = Class.forName(name, true,        result = Class.forName(name, true,
152                               VMSecurityManager.getClassContext()[1].getClassLoader());                               VMSecurityManager.getClassContext()[1].getClassLoader());
# Line 180  public final class Class implements Seri Line 180  public final class Class implements Seri
180     * @see ClassLoader     * @see ClassLoader
181     * @since 1.2     * @since 1.2
182     */     */
183    public static Class forName(String name, boolean initialize,    public static Class<?> forName(String name, boolean initialize,
184                                ClassLoader classloader)                                   ClassLoader classloader)
185      throws ClassNotFoundException      throws ClassNotFoundException
186    {    {
187      if (classloader == null)      if (classloader == null)
# Line 191  public final class Class implements Seri Line 191  public final class Class implements Seri
191          if (sm != null)          if (sm != null)
192            {            {
193              // Get the calling class and classloader              // Get the calling class and classloader
194              Class c = VMSecurityManager.getClassContext()[1];              Class<?> c = VMSecurityManager.getClassContext()[1];
195              ClassLoader cl = c.getClassLoader();              ClassLoader cl = c.getClassLoader();
196              if (cl != null)              if (cl != null)
197                sm.checkPermission(new RuntimePermission("getClassLoader"));                sm.checkPermission(new RuntimePermission("getClassLoader"));
198            }            }
199          if (name.startsWith("["))          if (name.startsWith("["))
200            return VMClass.loadArrayClass(name, null);            return VMClass.loadArrayClass(name, null);
201          Class c = VMClassLoader.loadClass(name, true);          Class<?> c = VMClassLoader.loadClass(name, true);
202          if (c != null)          if (c != null)
203            {            {
204              if (initialize)              if (initialize)
# Line 209  public final class Class implements Seri Line 209  public final class Class implements Seri
209        }        }
210      if (name.startsWith("["))      if (name.startsWith("["))
211        return VMClass.loadArrayClass(name, classloader);        return VMClass.loadArrayClass(name, classloader);
212      Class c = classloader.loadClass(name);      Class<?> c = classloader.loadClass(name);
213      classloader.resolveClass(c);      classloader.resolveClass(c);
214      if (initialize)      if (initialize)
215        VMClass.initialize(c);        VMClass.initialize(c);
# Line 289  public final class Class implements Seri Line 289  public final class Class implements Seri
289     * @see Array     * @see Array
290     * @since 1.1     * @since 1.1
291     */     */
292    public Class getComponentType()    public Class<?> getComponentType()
293    {    {
294      return VMClass.getComponentType (this);      return VMClass.getComponentType (this);
295    }    }
# Line 308  public final class Class implements Seri Line 308  public final class Class implements Seri
308     * @see #getConstructors()     * @see #getConstructors()
309     * @since 1.1     * @since 1.1
310     */     */
311    public Constructor getConstructor(Class[] types) throws NoSuchMethodException    public Constructor<K> getConstructor(Class... types)
312        throws NoSuchMethodException
313    {    {
314      memberAccessCheck(Member.PUBLIC);      memberAccessCheck(Member.PUBLIC);
315      Constructor[] constructors = getDeclaredConstructors(true);      Constructor[] constructors = getDeclaredConstructors(true);
# Line 353  public final class Class implements Seri Line 354  public final class Class implements Seri
354     * @see #getDeclaredConstructors()     * @see #getDeclaredConstructors()
355     * @since 1.1     * @since 1.1
356     */     */
357    public Constructor getDeclaredConstructor(Class[] types)    public Constructor<K> getDeclaredConstructor(Class... types)
358      throws NoSuchMethodException      throws NoSuchMethodException
359    {    {
360      memberAccessCheck(Member.DECLARED);      memberAccessCheck(Member.DECLARED);
# Line 482  public final class Class implements Seri Line 483  public final class Class implements Seri
483     * @see #getDeclaredMethods()     * @see #getDeclaredMethods()
484     * @since 1.1     * @since 1.1
485     */     */
486    public Method getDeclaredMethod(String methodName, Class[] types)    public Method getDeclaredMethod(String methodName, Class... types)
487      throws NoSuchMethodException      throws NoSuchMethodException
488    {    {
489      memberAccessCheck(Member.DECLARED);      memberAccessCheck(Member.DECLARED);
# Line 641  public final class Class implements Seri Line 642  public final class Class implements Seri
642            
643      public boolean equals(Object o)      public boolean equals(Object o)
644      {      {
645        if(o instanceof MethodKey)        if (o instanceof MethodKey)
646          {          {
647            MethodKey m = (MethodKey)o;            MethodKey m = (MethodKey) o;
648            if(m.name.equals(name) && m.params.length == params.length && m.returnType == returnType)            if (m.name.equals(name) && m.params.length == params.length
649                  && m.returnType == returnType)
650              {              {
651                for(int i = 0; i < params.length; i++)                for (int i = 0; i < params.length; i++)
652                  {                  {
653                    if(m.params[i] != params[i])                    if (m.params[i] != params[i])
654                      {                      return false;
                       return false;  
                     }  
655                  }                  }
656                return true;                return true;
657              }              }
# Line 687  public final class Class implements Seri Line 687  public final class Class implements Seri
687     * @see #getMethods()     * @see #getMethods()
688     * @since 1.1     * @since 1.1
689     */     */
690    public Method getMethod(String methodName, Class[] types)    public Method getMethod(String methodName, Class... types)
691      throws NoSuchMethodException      throws NoSuchMethodException
692    {    {
693      memberAccessCheck(Member.PUBLIC);      memberAccessCheck(Member.PUBLIC);
# Line 1006  public final class Class implements Seri Line 1006  public final class Class implements Seri
1006     * @throws NullPointerException if c is null     * @throws NullPointerException if c is null
1007     * @since 1.1     * @since 1.1
1008     */     */
1009    public boolean isAssignableFrom(Class c)    public boolean isAssignableFrom(Class<?> c)
1010    {    {
1011      return VMClass.isAssignableFrom (this, c);      return VMClass.isAssignableFrom (this, c);
1012    }    }
# Line 1244  public final class Class implements Seri Line 1244  public final class Class implements Seri
1244    }    }
1245    
1246    /**    /**
1247       * FIXME
1248       * @since 1.5
1249       */
1250      <T> public Class<? extends T> asSubclass(Class<T> klass)
1251      {
1252        if (! klass.isAssignableFrom(this))
1253          throw new ClassCastException();
1254        return (Class<? extends T>) klass;
1255      }
1256    
1257      /**
1258       * Return object, cast to this Class' type.
1259       *
1260       * @param obj the object to cast
1261       * @throws ClassCastException  if obj is not an instance of this class
1262       * @since 1.5
1263       */
1264      public K cast(Object obj)
1265      {
1266        return VMClassLoader.cast(obj, this);
1267      }
1268    
1269      /**
1270     * Like <code>getField(String)</code> but without the security checks and returns null     * Like <code>getField(String)</code> but without the security checks and returns null
1271     * instead of throwing NoSuchFieldException.     * instead of throwing NoSuchFieldException.
1272     */     */

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.22.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26