Exercise 4 - Box
The Basics
Box::equals(Object obj)
Box::equals(Object obj)@Override
public boolean equals(Object obj) {
if (obj instanceof Box<?>) {
Box<?> box = (Box<?>) obj;
return this.content.equals(box.content);
}
return false;
}Factory method
public static <T> Box<T> of(T obj) {
if (obj == null) {
return null;
}
return new Box<T>(obj);
}An Empty Box
static field of same generic type in a generic type
static field of same generic type in a generic typePECS
Implement Your Own Conditions
extends or implement a generic type - 1
extends or implement a generic type - 1Transforming a Box
Declare a type parameter in a non-static method
Box in a Box
extends or implement a generic type - 2
extends or implement a generic type - 2Last updated