[LANG][JAVA][int vs Integer]

·1 min read

int : primitive type

 

Integer : The {@Code Integer} class wraps a value of the primitive type {@code int}

 

package com.local.test;

/**

  • Hello world!

*/ public class App { public static void main( String[] args ) { System.out.println( "Hello World!" );

// int testInt = null; // System.out.println( "testInt : " + testInt ); /*Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from null to int */ Integer testInteger = null; System.out.println( "testInteger : " + testInteger );

Integer numInteger = 20; System.out.println( "numInteger : " + numInteger ); int numInt = numInteger; System.out.println( "numInt : " + numInt ); } }