如果我使用列表和相同的构造函数创建一个对象,这是否意味着在我创建之后我不能再引用它了?

时间:2020-12-26 08:40:27

I've created the following code to make Region objects that have information in them. (Coordinates, election data, etc). I'm wondering if I can no longer reference these after they are put into the memory (i.e. they are overwritten each time it goes through the object(Loop)) Thanks!

我创建了以下代码来创建包含信息的Region对象。 (坐标,选举数据等)。我想知道在将它们放入内存之后我是否再也不能引用它们了(即每次它通过对象时都被覆盖(循环))谢谢!

for (File object: fileList){
        try {
        region = new Region(object.getName());
            System.out.println(region);
        region.getSelection();
        } catch (Exception e) {

        }
    }

If I can, how would I reference that object? Excuse me if this question or a similar question has been answered. I couldn't find one similar enough to know what exactly this code does.

如果可以,我将如何引用该对象?如果这个问题或类似问题得到解答,请原谅。我找不到一个类似的足以知道这个代码究竟是做什么的。

1 个解决方案

#1


0  

Solution:

List<Region> regionList = new ArrayList<>();
List<File> fileList = new ArrayList<>(); 

   for (File object: fileList){
                try {
                regionList.add(new Region(object.getName()));
                region.getSelection();
                } catch (Exception e) {

                }
            }

#1


0  

Solution:

List<Region> regionList = new ArrayList<>();
List<File> fileList = new ArrayList<>(); 

   for (File object: fileList){
                try {
                regionList.add(new Region(object.getName()));
                region.getSelection();
                } catch (Exception e) {

                }
            }