java - 错误的资源泄漏警告?

标签 java eclipse compiler-warnings java-7 try-with-resources

我在这段代码中收到关于“s”和“p”的资源泄漏警告。这个警告有效吗?

try (StringWriter s = new StringWriter(); PrintWriter p = new PrintWriter(s)) {
    p.print(InetAddress.getLocalHost().getHostName());
    p.print('/');
    Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
    while (e.hasMoreElements()) {
        NetworkInterface i = e.nextElement();
        System.out.println(i);
        if (i.getHardwareAddress() == null || i.getHardwareAddress().length == 0)
            continue;
        for (byte b : i.getHardwareAddress())
            p.printf("%02x", b);
        return s.toString();
    }
    throw new RuntimeException("Unable to determine Host ID");
}

最佳答案

在这个片段中 - 没有。除了由 JVM 管理的资源外,没有其他资源可言。

关于java - 错误的资源泄漏警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13968184/

相关文章:

java - System.in.read();比较

java - 我应该在公共(public)类中使用静态类,还是只是一个单独的类

c - C中使用isxdigit()时如何处理数组下标警告?

android - 使用函数 gethostbyname 将 C 编译为静态链接错误

java - SpringData MongoDB 查询嵌套对象和列表对象

java - NoSuchBeanDefinition异常 : No qualifying bean of type 'org.springframework.mail.MailSender'

xml - 如何配置 Eclipse XML 格式?

java - 无法使用GAE运行Web项目

java.util.Map$Entry 类文件未找到

编译器警告 "result of malloc is converted to a point incompatible with sizeof operand type"