java - 编译时 Eclipse 给我一个奇怪的错误

标签 java eclipse debugging

我有一个返回数据类型 InetAddress[] 的函数

public InetAddress []
lookupAllHostAddr(String host) throws UnknownHostException {
    Name name = null;

    try {
        name = new Name(host);
    }
    catch (TextParseException e) {
        throw new UnknownHostException(host);
    }

    Record [] records = null;
    if (preferV6)
        records = new Lookup(name, Type.AAAA).run();
    if (records == null)
        records = new Lookup(name, Type.A).run();
    if (records == null && !preferV6)
        records = new Lookup(name, Type.AAAA).run();
    if (records == null)
        throw new UnknownHostException(host);

    InetAddress[] array = new InetAddress[records.length];
    for (int i = 0; i < records.length; i++) {
        Record record = records[i];
        if (records[i] instanceof ARecord) {
            ARecord a = (ARecord) records[i];
            array[i] = a.getAddress();
        } else {
            AAAARecord aaaa = (AAAARecord) records[i];
            array[i] = aaaa.getAddress();
        }
    }
    return array;
}

Eclipse 提示返回类型应该是 byte[][],但是当我将返回类型更改为 byte[][] 时,它提示该函数返回错误的数据类型。我陷入了循环。有谁知道这里发生了什么吗?

最佳答案

基于 lookupAllHostAddr 的一些研究揭示了以下内容:

sun.net.spi.nameservice.NameService 接口(interface)已更改 对于 JDK 6,Java 源代码无法 声明一个可以实现旧版本或新版本的类 (lookupAllHostAddr 方法的返回类型已从 byte[][]InetAddress[])。 使用 JDK 6 必须解决这个问题!

关于java - 编译时 Eclipse 给我一个奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2549797/

相关文章:

c++ - Eclipse C++ MinGW - 无法启动程序<已终止>

c++ - 代码块调试器在成员函数中时不显示类属性

c# - 如何在 C# 程序中放置 "IF DEBUG"条件?

java - Hashmap 方法不接受定义的参数

java - 如何使用 Java 知道数据来自 cassandra 中的哪个种子节点

java - 构建后某些设备上出现网络错误

java - spring:一个接收类列表的bean

java - 编译 : INSERT INTO table 时出现 Android SQLiteException "no such table"

java - Eclipse/Java/Android 无法执行 dex : Multiple dex files define

c++ - Cygwin GDB 在尝试启动程序时出现错误 193