feisty meow concerns codebase  2.140
instance_of.java
Go to the documentation of this file.
1 package test.java.semantics;
2 
3 import java.util.List;
4 
5 //hmmm: convert this to simple unit test.
6 class instance_of
7 {
8  public instance_of()
9  {
10  }
11 
12  public Object cogitate()
13  {
14  return null;
15  }
16 
17  public static void main(String s[]) throws Exception
18  {
19  // we are just asserting that it is safe to do instanceof on an object that is null.
20  // let's test that theory.
21  instance_of tony = new instance_of();
22  Object fred = tony.cogitate(); // will produce null.
23  if (fred instanceof List<?>) {
24  throw new Exception("FAILURE! fred should not be instance of List<?> ! null is an instance of something!");
25  } else {
26  System.out.println("told us null is not an instance of List, which is correct.");
27  }
28  }
29 }