我试图用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("")) ? …Run Code Online (Sandbox Code Playgroud)