On 10/25/12 3:37 PM, Justin Lee wrote:
> I'm clearly missing something here. How exactly would we be able to
> tell what they implemented? Because this test won't even compile:
>
> public class Handler {
> public interface MessageHandler<T> { }
>
> public static void main(String[] args) throws Exception {
> MessageHandler<String> handler = new MessageHandler<String>() {};
>
> System.out.println(handler instanceof MessageHandler<String>);
> }
> }
>
> So when a frame comes in, how are we going to decide which callback to
> call?
We can use reflection and generics filling.
for (Type t : handler.getClass().getGenericInterfaces()) {
System.out.println(" interface: " + t);
}
interface: qa.Test.qa.Test$MessageHandler<java.lang.String>
It's a bit more complicated than instanceof, but not too terrible. It
might make matching with Decoders more logical as well.
By the way, it seems a mismatch that the MessageHandler is assigned in
the session, but the decoder is assigned in the EndpointConfiguration.
I'd think their config should be at the same place (and setDecoders set
in the same place as setEncoders is.)
-- Scott