Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 1.7 incompatibility #6

Open
erelsgl opened this issue Feb 12, 2013 · 0 comments
Open

Java 1.7 incompatibility #6

erelsgl opened this issue Feb 12, 2013 · 0 comments

Comments

@erelsgl
Copy link

erelsgl commented Feb 12, 2013

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant