//BoxNonGenericDemo.java
//Demonstrates the BoxNonGeneric class by creating two
//different class objects, one with an Integer private
//data member, and one with a String private data member.
//Note A cast is required when retrieving the stored value.

public class BoxNonGenericDemo
{
    public static void main(String args[])
    {
        BoxNonGeneric object1;
        BoxNonGeneric object2;

        System.out.println();

        object1 = new BoxNonGeneric(123); //Autoboxing required
        object1.showType();
        int intValue = (Integer) object1.getObject(); //Cast required
        System.out.println("value: " + intValue);

        System.out.println();

        object2 = new BoxNonGeneric("Have a nice day!");
        object2.showType();
        String stringValue = (String) object2.getObject(); //Cast required
        System.out.println("value: " + stringValue);

        System.out.println();

        object1 = object2; //Compiles, but is conceptually wrong!
        //int i = (Integer) object1.getObject();   //Compiles, but runtime error!
        String s = (String) object1.getObject(); //OK, but confusing
        object1.showType();
        System.out.println("value: " + s);
    }
}

/*Output:

Type of object is java.lang.Integer
value: 123

Type of object is java.lang.String
value: Have a nice day!

Type of object is java.lang.String
value: Have a nice day!
*/
