Java编译器为什么会给出“错误:找不到符号”?以下代码中的LinkedList降序Iterator? [英] Why does Java compiler give "error: cannot find symbol" for LinkedList descendingIterator in the following code?

查看:85
本文介绍了Java编译器为什么会给出“错误:找不到符号”?以下代码中的LinkedList降序Iterator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要这段代码:

import java.util.*;
class Playground {
    public static void main(String[ ] args) {
        List<Integer> l = new LinkedList<>();
        Iterator<Integer> i = l.descendingIterator();
    }
}

生成此编译器错误

./Playground/Playground.java:5: error: cannot find symbol
        Iterator<Integer> i = l.descendingIterator();
                               ^
  symbol:   method descendingIterator()
  location: variable l of type List<Integer>
1 error




  • 以下是相关的 JavaDocs API

  • 正在运行Java7。如果出现问题。以为它已经存在多年了。

  • 这里是其他地方的罐头示例。

  • 您可以从此处将代码复制/粘贴到此网站查看

    • Here is the relevant JavaDocs API
    • Running Java 7.. In case that is issue. Thought it had been around for donkeys years.
    • Here is a canned example elsewhere.
    • You could copy/paste code from here into this website to see,
    • 推荐答案


      List是接口,而LinkedList是List的实现

      List is an interface and LinkedList is an implementation of List

      您可以选择像

      Iterator<Integer> i = ((LinkedList<Integer>)l).descendingIterator();
      

      或将代码更改为以下内容:

      or change your code to be the following:

      import java.util.*;
      class Playground {
          public static void main(String[ ] args) {
              LinkedList<Integer> l = new LinkedList<>();
              Iterator<Integer> i = l.descendingIterator();
          }
      }
      

      这篇关于Java编译器为什么会给出“错误:找不到符号”?以下代码中的LinkedList降序Iterator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆