It looks very good for me, you can use the extend keyword on generics to insure type safety and to avoid unnecessary casts. And this is called a Bounded type
class StackMinimum<T extends Comparable>{
public void push(T item) {
stack1.push(item);
// to need for the cast here
if (stack2.isEmpty() || item.compareTo(stack2.peek()) < 0) {
stack2.push(item);
}
}
}
Only Comparable type wouldtypes will be welcomed in your stack