gpt4 book ai didi

java - Java Gxt 中 ListStore 的迭代

转载 作者:行者123 更新时间:2023-11-30 03:36:48 26 4
gpt4 key购买 nike

所以我正在 java 中使用网格小部件...并且当尝试迭代 ListStore 时出现以下错误。

[javac]   required: array or java.lang.Iterable
[javac] found: ListStore<String>

关于如何解决这个问题/为此创建迭代器有什么建议吗?

这是我的代码:

public void cycle(ListStore<String> line_data){

for(LineObject line: line_data){
//Other code goes here
}


}

最佳答案

如javadoc所示List Store不实现Iterable 。因此您无法使用 foreach 循环对其进行迭代。

只需使用 getAll() List Store 的方法会返回 java.util.List它正确地实现了 Iterable。

但另一个问题是您正在尝试使用 LineObject 进行迭代自从你的 ListStore 以来,这将不起作用使用 String 声明即ListStore<String>而不是ListStore<LineObject>

这里是一些示例代码:

public void cycle(ListStore<String> line_data){

List<String> lineListData = line_data.getAll();

//for(LineObject line: lineListData){ <-- won't work since you are using Strings

for(String line: lineListData){ // <-- this will work but probably not what you want
//Other code goes here
}

}

回顾您对问题的编辑,您可能只想使用 LineObject :

public void cycle(ListStore<LineObject> line_data){

List<LineObject> lineListData = line_data.getAll();

for(LineObject line: lineListData){
//Other code goes here
}

}

关于java - Java Gxt 中 ListStore 的迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27710980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com