I write a program to check whether a given IP address is Any Local Address or not as:
import java.net.*;
class GetByName
{
public static void main(String[] args) throws Exception
{
byte[] b = {0, 0, 0, 0};
String s = "abc";
InetAddress in = InetAddress.getByAddress(b);
boolean b1 = in.isAnyLocalAddress();
System.out.println(in);
System.out.println(b1);
}
}
And the output is:
/0.0.0.0
true
Yes, looking quite normal. But I shocked when I see the implementation of isAnyLocalAddress() in InetAddress.java.
public boolean isAnyLocalAddress() {
return false;
}
Means anyhow this method has to return false. Then how this method returns true in my program?