dev@grizzly.java.net

Re: Purpose of com.sun.grizzly.util.Copyable is not clear ...

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Mon, 29 Jun 2009 13:52:24 +0200

Hi Kedar,


> In general, I am not clear on the purpose of this Java interface
> which is used all over. In all the *usages* of implementations of
> this interface, the copyTo method just typecasts the given parameter
> to an expected type and it either results in ClassCastException or
> returns abruptly if the passed parameter is not of expected type.
> Thus, the caller *has to* pass the correct type. For example,
> TCPSelectorHandler.copyTo does:
>
> TCPSelectorHandler copyHandler = (TCPSelectorHandler) copy;
>
> and happily proceeds. Now, unless caller passes in an instance of
> TCPSelectorHandler (which is what happening all the time), this
> method will fail throwing CCE.
>
> Now, my question is, if the above is true, what is the use of this
> interface? It serves the purpose of neither a classic copy
> constructor, nor is it a cloner (in traditional Java sense of
> Cloning). In general, it is not possible to copy a generic class
> unless you know its internal structure, because all the
> implementations are basically resulting in a bunch of setters.
>
> Am I missing something?
Copyable interface together with utility class Cloner implements
custom cloning mechanism in Grizzly 1.x. This is used just internally
inside framework, so normally CCE should not occur.

WBR,
Alexey.

>
> -Kedar
>