In your second example, you're not passing socket
to socketHandler
, so you cannot expect socketHandler
to know about it.
You could solve this by creating a method like createSocketHandler(final Socket socket)
that returns a Handler<Message>
and that replaces your socketHandler
variable.
To learn more, and to find out why you need socket
to be final
, look up "anonymous inner classes"