Reputation: 10437
Am I using generics in the wrong way? Sorry I'm new to generics.
public interface Stream {
public <T extends InputStream> void read(T in);
}
public class StreamReader implements Stream {
@Override
public <T extends InputStream> void read(T in) {
ByteInputStream bis = (ByteInputStream) in;
...
}
Upvotes: 0
Views: 31
Reputation: 2208
You can change your method from:
public <T extends InputStream> void read(T in);
To:
public <T extends InputStream> void read(<T extends ByteInputStream> in);
Upvotes: -1
Reputation: 8068
I think you are in search of this:
public interface Stream<T extends InputStream> {
public void read(T in);
}
public class StreamReader implements Stream<ByteArrayInputStream> {
@Override public void read(ByteArrayInputStream in) {
...
}
}
Upvotes: 4