"oziris" <> wrote in news:1132750729.714005.108840
@g47g2000cwa.googlegroups.com:
> I had to write a specific Socket class. So now I would
> ServerSocket.accept() returns an instance of this class.
>
> The instruction
>
> MySocket socket = (MySocket)serverSocket.accept();
>
> throws a ClassCastException.
>
> According to a reply to the same message on fr.comp.lang.java, the
> means seems to consist in extend SocketImpl and related classes.
>
> -o--
>
That's not the same code as what you gave in the original post
This of course fails because serverSocket.accept() returns a Socket, not
MySocket. MySocket is a Socket, but not the other way around. The
SocketFactory method mentioned in the other post could work, or you can do
what you originally said:
MySocket socket = new MySocket(serverSocket.accept());
The SocketFactory way is cleaner, but more typing.