I am trying to define a generic method whose parameter is bound by two types, but it doesn't seem to work:
public static <T extends Readable, Appendable> void doSomething(T t) {
int r = t.read(...); // compiles OK
//
t.append(...); // compile error
}
This should compile. Can anyone see what I'm doing wrong?
The problem is that the method defines two parameters, one called T and one called Appendable, not one parameter with two bounds.
The comma should be an ampersand, like this:
public static <T extends Readable & Appendable> void doSomething(T t) {
//
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With