我在我的Java开发程序包中检查了代码InetAddress
类文件,我会看到以下行。
线号:302-308
/**
* Constructor for the Socket.accept() method.
* This creates an empty InetAddress, which is filled in by
* the accept() method. This InetAddress, however, is not
* put in the address cache, since it is not created by name.
*/
InetAddress() {
holder = new InetAddressHolder();
}
在上面的代码中,我可以看到InetAddress
类修饰符是default
不是private
,那么我们也不能使用新方法创建InetAddress
类的对象。喜欢以下
InetAddress addr = new InetAddress();
您可以....但是您不应该....
记住友好的含义作为可见性概念...
如果您通过省略,疏忽或错误定义了用名称 java.net;
的包裹然后以下
InetAddress v = new InetAddress();
将有效..
再次... 不是您无法做的事情...是您不应该做的事情!
最好永远不要用SDK软件包名称定义自己的包裹,否则您会得到
等例外java.lang.securityException:禁止的包装名称:java.net