Skip to content

Commit 212ec2d

Browse files
committed
Challenge 40.
null value regarding instanceof.
1 parent 5826adb commit 212ec2d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package challenge31_40;
2+
3+
import java.util.ArrayList;
4+
import java.util.concurrent.atomic.AtomicInteger;
5+
6+
/**
7+
* If we son't initialize the t instance variable, it will be equals to null;
8+
* the null value can create many problems as the example below
9+
*
10+
*/
11+
public class Challenge_40 <T> {
12+
13+
T t;
14+
15+
public static void main( String[] args ) {
16+
doStuffWithNullValue(null);
17+
18+
if (null instanceof Object)
19+
System.out.println("null is instance of object");
20+
if(null instanceof AtomicInteger)
21+
System.out.println("null is instance of AtomicInteger");
22+
if(null instanceof StackOverflowError)
23+
System.out.println("null is instance of StackOverflowError");
24+
if (new ArrayList<>() instanceof Cloneable)
25+
if (new String() instanceof CharSequence)
26+
if (new Challenge_40<>().t instanceof Object)
27+
System.out.println("Exception");
28+
29+
}
30+
31+
private static void doStuffWithNullValue( Integer number ) {
32+
if (number instanceof Integer)
33+
System.out.println("Do some logic .....");
34+
}
35+
}

0 commit comments

Comments
 (0)