2 ms·
A great example of this is ByteArrayOutputStream's close(). It's documented to do literally nothing, and yet you still have to "handle" an IOException that will
by kllrnohj 6y ago
A great example of this is ByteArrayOutputStream's close(). It's documented to do literally nothing, and yet you still have to "handle" an IOException that will never, ever happen.
https://docs.oracle.com/javase/7/docs/api/java/io/ByteArrayOutputStream.html#close() https://docs.oracle.com/javase/7/docs/api/java/io/ByteArrayO...
- hyperpape 6y agoThe language doesn't force them to do that--they could override the interface and not declare the Exception. Then if you were working with an object declared to be ByteArrayOutputStream, you wouldn't need to handle the Exception. If working with the interface, you would, because that's the point of an interface.
- twic 6y agoYes, this is a poor example. The declaration of that exception is either a mistake, or a way of reserving some wiggle room for future changes.