Last active
December 23, 2015 14:39
-
-
Save hellojinjie/6650799 to your computer and use it in GitHub Desktop.
sun.net.www.protocol.http.HttpURLConnection.java 中一段很搞的代码。 内部匿名类无法访问外面的非 final 的变量。这里用数组的形式进行 workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final boolean result[] = {false}; | |
java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { | |
public Object run() { | |
try { | |
InetAddress a1 = InetAddress.getByName(h1); | |
InetAddress a2 = InetAddress.getByName(h2); | |
result[0] = a1.equals(a2); | |
} catch (UnknownHostException e) { | |
} catch (SecurityException e) { | |
} | |
return null; | |
} | |
}); | |
return result[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment