I am having trouble understanding a part of class slide that says:
Storing Items in an ArrayBag :
We store the items in an array of type Object.
public class ArrayBag implements Bag {
private Object[] items;
private int numItems;
....
}
This allows us to store any type of object in the items array, thanks to the power of polymorphism:
ArrayBag bag = new ArrayBag();
bag.add("hello");
bag.add(new Double(3.1416));
Is ArrayBag a specific type of object or is it just a Obj variable name?
Why do we need to cast 3.1416 as a Double and add a new?
(I know the code could be just be bag.add(3.1416) and Java will autobox it for you, but I'm having trouble understanding the meaning behind bag.add(new Double(3.1416)).