【发布时间】:2018-04-26 11:08:17
【问题描述】:
我正在尝试使用对 getMyClassTypes() 的递归调用来填充列表 myClassTypes。但是每次递归调用该方法时它都会被初始化。而且,我因此失去了一些价值。我知道问题在于在本地声明: List myClassTypes = new ArrayList(); 但是,我不想在类级别声明列表。 这是我正在使用的代码:
private List<MyClassType> getMyClassTypes(final String path) throws SVNException {
final Collection<SVNDirEntry> svnDirectoryEntries = svnRepository.getDir(path, -1, null, (Collection<SVNDirEntry>) null);
final Iterator<SVNDirEntry> svnDirectoryEntryIterator = svnDirectoryEntries.iterator();
final List<MyClassType> myClassTypes = new ArrayList<>();
while (svnDirectoryEntryIterator.hasNext()) {
final SVNDirEntry entry = svnDirectoryEntryIterator.next();
final String fileName = entry.getName();
if (!path.isEmpty() && path.matches(SUB_DIRECTORY_NAME_PATTERN) && fileName.endsWith(".xml")) {
final MyClassType myClassType = new MyClassType(path, fileName);
myClassTypes.add(myClassType);
}
/*
* Check if the entry is a directory recursively.
*/
if (someCondition) {
getMyClassTypes((path.equals("")) ? entry.getName() : path + "/" + entry.getName());
}
}
return myClassTypes;
}
即使在“n 次”递归调用之后,如何管理“myClassTypes”以包含所有值?
【问题讨论】:
-
你的意思是你会打电话给
getMyClassTypesn次?
标签: java list recursion arraylist