Have a look at this (arguably stupid) code:
public <T extends Appendable & Closeable> void doStuff(T object)
throws IOException{
object.append("hey there");
object.close();
}
I know that the compiler removes generic information, so I'm interested in Java 1.4 code equivalent to what the compiler does (I'm pretty sure the compiler doesn't rearrange the source code, so I am asking for an equivalent Java source version which naive people like myself can understand)
Is is something like this:
public void doStuff(Object object)
throws IOException{
((Appendable)object).append("hey there");
((Closeable)object).close();
}
Or rather like this:
public void doStuff(Object object)
throws IOException{
Appendable appendable = (Appendable) object;
Closeable closeable = (Closeable) object;
appendable.append("hey there");
closeable.close();
}
Or even like this:
public void doStuff(Appendable appendable)
throws IOException{
Closeable closeable = (Closeable) appendable;
appendable.append("hey there");
closeable.close();
}
Or yet another version?