我有接收功能的MethodDeclaration
:如何在MethodDeclaration類中返回迭代器類型?
public boolean visit(MethodDeclaration node){ }
我需要通過樹(從node
開始)進行迭代,所以我宣佈:
Iterator<MethodDeclaration> itr;
在
for循環,並用它像這樣的:
for(Iterator<MethodDeclaration> itr = node; itr.hasNext();)
所以我的功能看起來像這樣至今:
public boolean visit(MethodDeclaration node)
{
if (node != null)
{
for (Iterator<MethodDeclaration> itr = node; itr.hasNext();)
{
....
}
}
}
itr
聲明和itr.hasNext()
正在工作(日食標識他們)。但行Iterator<MethodDeclaration> itr = node;
不是。我顯然需要激活node
中的某種方法,該方法返回iterator
類型。但我找不到任何。
我該怎麼辦?
感謝
你的'MethodDeclaration'是否實現'Iterator'?如果不是,你不能使用迭代器。您可能需要使用while來遍歷節點。 –
你想重複什麼? –