Hi,
The interface definition is incorrect IMHO. It should look like this.
public interface Vehicle<T> {
public T copy();
}
public class Car implements Vehicle<Car> {
@Override
public Car copy() {
return null;
}
}
public class Boat implements Vehicle<Boat> {
@Override
public Boat copy() {
return null;
}
}
But it is even better if you separate the interfaces.
public interface Vehicle {}
public interface Copyable<T extends Vehicle>{
T copy();
}
public class Car implements Vehicle, Copyable<Car> {
@Override
public Car copy() {
return null;
}
}
public class Boat implements Vehicle, Copyable<Boat> {
@Override
public Boat copy() {
return null;
}
}
Then you can use
Car c = new Car()
Vehicle v = c.copy()