MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / test

Method test

reflection/FamilyVsExactType.java:13–37  ·  view source on GitHub ↗
(Object x)

Source from the content-addressed store, hash-verified

11
12public class FamilyVsExactType {
13 static void test(Object x) {
14 System.out.println(
15 "Testing x of type " + x.getClass());
16 System.out.println(
17 "x instanceof Base " + (x instanceof Base));
18 System.out.println(
19 "x instanceof Derived " + (x instanceof Derived));
20 System.out.println(
21 "Base.isInstance(x) " + Base.class.isInstance(x));
22 System.out.println(
23 "Derived.isInstance(x) " +
24 Derived.class.isInstance(x));
25 System.out.println(
26 "x.getClass() == Base.class " +
27 (x.getClass() == Base.class));
28 System.out.println(
29 "x.getClass() == Derived.class " +
30 (x.getClass() == Derived.class));
31 System.out.println(
32 "x.getClass().equals(Base.class)) "+
33 (x.getClass().equals(Base.class)));
34 System.out.println(
35 "x.getClass().equals(Derived.class)) " +
36 (x.getClass().equals(Derived.class)));
37 }
38 public static void main(String[] args) {
39 test(new Base());
40 test(new Derived());

Callers 1

mainMethod · 0.95

Calls 1

equalsMethod · 0.45

Tested by

no test coverage detected