Skip to content

Java 1.7 incompatibility #6

Description

@erelsgl

In Java 1.7, the following code produces a compile-time error:

    final IOSocket socket = new IOSocket("http://localhost:4000", new MessageCallback() {
        @Override public void onConnect() {
            try {
                socket.emit("start_session", ....

The error is: "The local variable socket may not have been initialized".

A possible solution is to create the callback, not in the constructor but only after the constructor. A small addition is required in IOSocket to support this:

public IOSocket(String address){
    webSocketAddress = address;
    this.callback = null;
}

public IOSocket setCallback(MessageCallback callback){
    this.callback = callback;
    return this;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions