4

这个简单的例子演示了这个问题:

public class Main {
    interface Person {
        default int amountOfHands() {
            return 2;
        }
    }

    public static class BasicPerson implements Person {

        int numberOfFaces() {
            return 1;
        }
    }

    public static void main(String[] args) {
        System.out.println("Put a breakpoint here");
    }
}

我在 IntelliJ IDEA 中以调试模式运行此代码,并将两个手表放在 main 方法中:

new BasicPerson().amountOfHands();

new BasicPerson().numberOfFaces();

这两种方法都应该返回一个原始 int,但是只有第二个 watch(类方法)显示一个原始 int,而第一个(默认接口方法)显示一个装箱的 Integer 对象。

手表

这是为什么?那是一个错误吗?

4

1 回答 1

4

我想这是 IntelliJ IDEA 中的一个错误。在 Eclipse 中,这两个表达式都按预期计算为原始值。

于 2015-05-05T01:53:33.977 回答