-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFamilyVsExactType.java
More file actions
33 lines (26 loc) · 1.12 KB
/
FamilyVsExactType.java
File metadata and controls
33 lines (26 loc) · 1.12 KB
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
package typeinfo;
/**
* RUN:
* javac typeinfo/FamilyVsExactType.java && java typeinfo.FamilyVsExactType
* OUTPUT:
*
*/
public class FamilyVsExactType {
static void test(Object x) {
System.out.println("Testing x type of " + x.getClass());
System.out.println("x instanceof Base " + (x instanceof Base));
System.out.println("x instanceof Derived " + (x instanceof Derived));
System.out.println("Base.isInstance(x) " + Base.class.isInstance(x));
System.out.println("Derived.isInstance(x) " + Derived.class.isInstance(x));
System.out.println("x.getClass() == Base.class " + (x.getClass() == Base.class));
System.out.println("x.getClass() == Derived.class " + (x.getClass() == Derived.class));
System.out.println("x.getClass().equals(Base.class) " + (x.getClass().equals(Base.class)));
System.out.println("x.getClass().equals(Derived.class) " + (x.getClass().equals(Derived.class)));
}
public static void main(String[] args) {
test(new Base());
test(new Derived());
}
}
class Base {}
class Derived extends Base {}