Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4090364

(reflect) Class.isAssignableFrom incorrect for array classes

XMLWordPrintable

    • 1.1.8
    • x86
    • windows_95
    • Not verified



        Name: chT40241 Date: 11/03/97


        The method java.lang.Class.isAssignableFrom does not always return
         a correct result when array types are involved. A simple test case is
         is follows:
                                                                                    
         public class TestCase {
           public static void main(String argv..)
           {
            int ai[][] = new int[5][5];
            Object ao[] = ai;
            ao = new Object[1];
            if (!ao.getClass().isAssignableFrom(ai.getClass()))
             System.out.println("Not assignable!");
           }
         }
                                                                                    
         In this example, the class int[][] is indeed assignable to the type
         Object[], as is shown by the compiler's acceptance of the assignment
         of ai to ao, and its successful execution at run-time. However,
         the Class.isAssignable method indicates the opposite. I note that
         the documentation for isAssignableFrom specifically cites Section
         5.1.4 of the Java Language Spec, according to which this assignment is permitted.

        ======================================================================

              bgomessunw Benedict Gomes (Inactive)
              chickeysunw Chuck Hickey (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: