
















/** Autoboxing
 
    Integer b;
    b= 25;      // Illegal in java version 4: the types
                // of variable and expression don't match.
                
    int i;
    i= b;       // Illegal in java version 4: the types
                // of variable and expression don't match.

 =====================
 
    The assignments work in Java version 5 and later
    because of the introduction of "autoboxing".
    
    Autoboxing (and autounboxing) is just a convenience,
    allowing code to be shortened.
    
    Autoboxing works with all primitive types and their
    wrapper classes.
    
    Rule for autoboxing an int:
    
        If an expression e (say) of type int appears in
        a position in which an object of class Integer 
        is expected (or possible), the expression new 
        Integer(e) is used in place of e.
        
    Rule for autounboxing an int:
    
        If an expression e (say) of type Integer appears
        in a position in which an expression of type int
        is expected, then the expression e.intValue() is
        used in place of e.
 
 */

public class AutoboxDemo {
    
    /** = "obj is 5". */
    public static boolean isFive(Integer obj) {
        return obj.equals(new Integer(5));
    }
    
    /** = "c is 4". */
    public static boolean isFour(int c) {
        return c == 4;
    }
    
}