Box vs GenericBox: A Java Showdown

Report a typo

Consider the following classes in Java:

public class Box { 
    private Object object; 
    public void set(Object object) { this.object = object; } 
    public Object get() { return object; } 
}

public class GenericBox<T> { 
    private T t; 
    public void set(T t) { this.t = t; } 
    public T get() { return t; } 
}

Which are the fundamental differences and benefits of using the GenericBox class over the Box class when dealing with different types of objects?

Select one or more options from the list

Create a free account to access the full topic