创建Iterable并直接传入值

时间:2022-01-17 18:52:02

In an app I am working on, I want to return an Iterable or a subclass of Iterable and pass in the values directly. So I'm trying to do something like this:

在我正在处理的应用程序中,我想返回Iterable的Iterable或子类,并直接传入值。所以我想尝试这样的事情:

private CustomClass valueOne;
private CustomClass valueTwo;

public Iterable<? extends CustomClass> children() {
    return Array.asList(valueOne, valueTwo);
}

The thing is, asList doesn't seem to work. Is there anything like this that I could use? I've been searching but I can't seem to find anything that works in my case.

问题是,asList似乎不起作用。我可以使用这样的东西吗?我一直在寻找,但我似乎无法找到任何适用于我的情况。

1 个解决方案

#1


1  

change

更改

Array.asList

to

Arrays.asList

asList method is available on Arrays class not in Array

asList方法在Arrays类上不在Array中

List<CustomClass> list= Arrays.asList(new CustomClass[]{valueOne,valueTwo});

#1


1  

change

更改

Array.asList

to

Arrays.asList

asList method is available on Arrays class not in Array

asList方法在Arrays类上不在Array中

List<CustomClass> list= Arrays.asList(new CustomClass[]{valueOne,valueTwo});

相关文章