gpt4 book ai didi

Java networkinterface.isVirtual() 方法总是返回值是 false?

转载 作者:行者123 更新时间:2023-12-01 22:06:37 26 4
gpt4 key购买 nike

什么情况下返回值为true?

谢谢大家!

public class Test1 {

public static void main(String[] args) {
try {
Enumeration<NetworkInterface> networkInterface = NetworkInterface
.getNetworkInterfaces();
while (networkInterface.hasMoreElements()) {
NetworkInterface eachNetworkInterface = networkInterface
.nextElement();
System.out.println(eachNetworkInterface.getName() + " "
+ eachNetworkInterface.isVirtual());
}
} catch (SocketException e) {
e.printStackTrace();
}

}

}

打印结果全部错误!为什么?如何打印 true?

最佳答案

根据javadocs :

Returns whether this interface is a virtual interface (also called subinterface). Virtual interfaces are, on some systems, interfaces created as a child of a physical interface and given different settings (like address or MTU). Usually the name of the interface will the name of the parent followed by a colon (:) and a number identifying the child since there can be several virtual interfaces attached to a single physical interface.

如果您得到的结果均为false,则仅意味着您的系统中没有创建任何子接口(interface)。

关于Java networkinterface.isVirtual() 方法总是返回值是 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32651463/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com