How can I require a method argument in Java to implement multiple interfaces?
It's legal to do this in Java: void spew(Appendable x) { x.append("Bleah!\n"); } How can I do this (syntax not legal): void spew(Appendable & Closeable x) { x.append("Bleah!\n"); if (timeToClose()) x.close(); } I would like if possible to force callers to use objects that are both Appendable and Closeable, without requiring a specific type. There are multiple standard classes that do this, e.g. BufferedWriter, PrintStream, etc. If I define my own interface interface AppendableAndCloseable extends Appendable, Closeable {} that won't work since the standard classes that implement Appendable and