今天上班看到一块代码,让我大吃一惊,原来空对象也可以点方法,有兄弟知道什么原理吗?求赐教
package test;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Test {
public static void main(String[] args) {
InetAddress ia = null;
String ip = null;
try {
ia = ia.getLocalHost();
ip = ia.getHostAddress();
System.out.println("本地IP地址为:" + ip);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}