I encounter this error whilst compiling the source. The code is as below:
public final class A{
private final MulticastSocket socket;
public A(int port){
try{
this.socket = new MulticastSocket(port);
}catch(Exception e){}
}
}
The error says `Variable socket might not have been initialized.'
After reading http://java.sun.com/docs/books/jls/second_edition/html/defAssign.doc.html, I think this might be from the construction with try ... catch statement because it is not guaranteed to be executed `as the rules of definite assignment are concerned'.
How can I avoid this error? (I notice I can replace try catch block with `public A (int port) throws Exception' to avoid this compilation error, but this is not what I want.)
I appreciate any suggestion.