the following java class declaration is incorrect:
public class BookKeeping<T extends Transaction<K extends Money>> { ... }
here, one cannot use the generic declaration K extends Money.
my question is why this declaration is not allowed? And how should one declare such a class with java generics?
solution
class Money {
}
class Dollar extends Money {
}
class Transaction<T extends Money> {
}
public class BookKeeping<K extends Money,T extends Transaction<K>> {
public void foo () {
Dollar d = new Dollar();
Transaction<Dollar> t = new Transaction<Dollar>();
BookKeeping<Dollar, Transaction<Dollar>> b = new BookKeeping<Dollar, Transaction<Dollar>>();
}
}
You need to specify the generic parameters and the appropriate constraints and then use them for any anything additional.