使用通配符时,某些方法(例如ArrayList.set
)无法使用,并返回类似于以下内容的错误消息
The method set(int, capture#3-of ?) in the type List is not applicable for the arguments (int, String)
我已阅读why情况就是这样,想知道这是如何做到的。这就是编译器如何知道某些方法适用(例如 List.get(int)
)但其他方法不适用?
最佳答案
所有适用的规则都在 Java Language Specification #15.12 中.
关于java - java编译器如何确定 'method not applicable'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14210928/