简体   繁体   中英

Why does InetAddress.isSiteLocalAddress() in Java source code always returns false

I was checking the source file of java.net.InetAddress Class and found that few methods always return false. For example

/**
 * Utility routine to check if the InetAddress is a site local address. 
 *
 * @return a <code>boolean</code> indicating if the InetAddress is 
 * a site local address; or false if address is not a site local unicast address.
 * @since 1.4
 */
public boolean isSiteLocalAddress() {
return false;
}

Am I missing something? Why would we need a method that always returns false? It is same for all the methods starting with 'is' in this Class. See http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/net/InetAddress.java

InetAddress has some subclasses that override those methods and return useful results.

Like Inet4Address: It returns true if the address is "local" according to RFC 1918. There's a line comment:

// refer to RFC 1918
// 10/8 prefix
// 172.16/12 prefix
// 192.168/16 prefix

For a context free internet address (= not IPv4 and not IPv6) it makes sense to return false because local site doesn't exist without a context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM