import java.io.IOException;
import java.io.UnsupportedEncodingException;
interface Callback<E extends Exception> {
void call() throws E;
}
class DuplexCallback<E extends Exception> implements Callback<E> {
private final Callback<? extends E> first;
private final Callback<? extends E> second;
public DuplexCallback(
final Callback<? extends E> first,
final Callback<? extends E> second)
{
this.first = first;
this.second = second;
}
public void call() throws E {
first.call();
second.call();
}
}
class RuntimeExceptionAdapterCallback<E extends Exception>
implements Callback<E>
{
private final Callback<? extends RuntimeException> callback;
public RuntimeExceptionAdapterCallback(
final Callback<? extends RuntimeException> callback)
{
this.callback = callback;
}
public void call() {
callback.call();
}
}
class LoggingCallback implements Callback<RuntimeException> {
public void call() {
System.
out.
println("call() called"); }
}
class BytesLoggingCallback implements Callback<UnsupportedEncodingException> {
private final byte[] bytes;
public BytesLoggingCallback(final byte[] bytes) {
this.bytes = bytes;
}
}
}
public class Main {
Callback<IOException> callback =
new DuplexCallback<>(
new RuntimeExceptionAdapterCallback<IOException>(
new LoggingCallback()),
new BytesLoggingCallback(new byte[]{65}));
callback.call();
}
}