You are working in a Pie company. The business is going well and bakeries are selling abroad. Sometimes due to customs rules and trade regulations, it is necessary to package bakeries in a box with a more basic name like Bakery or Food. The full class hierarchy follows:
class Food {}
class Bakery extends Food {}
class Cake extends Bakery {}
class Pie extends Bakery {}
class Tart extends Bakery {}
interface Box<T> {
public void put(T item);
public T get();
}
There is a Packer class available, but it is designed with business rule violations and lacks implementation. Correct the Packer code to ensure that:
- Any kind of Bakery could be repacked in a Box with a more basic type (e.g. from a box with Pie to a box with Food)
- Basic stuff like food can't be repacked into narrowly typed Boxes (e.g. with Cakes)
- Arbitrary stuff like Strings or Objects can't be repacked without compile-time errors or warnings
- Repacking actually happens
If this task takes too much time, try to skip it.