summaryrefslogtreecommitdiffstats
path: root/libjava/testsuite/libjava.lang/Class_1.java
blob: 58df6beace54e04e6f49f2d6ad0ec6c39488820a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class C {}
class D extends C implements I {}
interface I {}
interface J extends I {}

public class Class_1
{
  static void printIsAssignableFrom(Class a, Class b, boolean c)
    {
      // The field 'c' can be viewed to see the expected value.
      System.out.println(a.isAssignableFrom(b));
    }

  public static void main (String arg[])
  {
    System.out.println("Testing class `Class_1'...");
    printIsAssignableFrom(C.class, Object.class, false);
    printIsAssignableFrom(C.class, C.class, true);
    printIsAssignableFrom(C.class, D.class, true);
    printIsAssignableFrom(D.class, C.class, false);

    printIsAssignableFrom(Object.class, int[].class, true);
    printIsAssignableFrom(int[].class, int[].class, true);
    printIsAssignableFrom(C[].class, D.class, false);
    printIsAssignableFrom(C[].class, D[].class, true);
    printIsAssignableFrom(C[].class, C[][].class, false);

    printIsAssignableFrom(Object.class, I.class, true);
    printIsAssignableFrom(I.class, I.class, true);
    printIsAssignableFrom(D.class, I.class, false);
    printIsAssignableFrom(I.class, D.class, true);

    printIsAssignableFrom(D.class, J.class, false);
    printIsAssignableFrom(J.class, D.class, false);

    printIsAssignableFrom(I.class, J.class, true);
    printIsAssignableFrom(J.class, J.class, true);
    printIsAssignableFrom(J.class, I.class, false);

    // Returns true iff both Class objects are equal.
    printIsAssignableFrom(long.class, long.class, true);

    // Does not work for primitive types in general.
    printIsAssignableFrom(long.class, int.class, false);
  }
}
OpenPOWER on IntegriCloud