File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
src/main/java/challenge31_40 Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments