简体   繁体   English

访问扩展ArrayList的对象元素

[英]Accessing elements of object that extends ArrayList

I'm pretty new to Java, and I'm trying to program an app that displays a list of points on a map. 我是Java的新手,我正在尝试编写一个在地图上显示点列表的应用程序。 I've got that much working, now I want to work out the boundaries of the places to set the zoom area. 我有那么多工作,现在我想弄清楚地方的边界来设置缩放区域。 To do this I have created a class that contains all my place objects, extending ArrayList() as below: 为此,我创建了一个包含所有place对象的类,扩展了ArrayList(),如下所示:

public class PlaceList extends ArrayList<Place> {
private static final long serialVersionUID = 4374092139857L;

public PlaceList() {
}

public Double getNorthernLimit() {
   double mostNorthern;
       for (Place curPlace: ???????) {
        //check each place and keep most northern one
       }

   return mostNorthern;
}

My problem is that I don't know how to access the Arraylist of objects (where the ??? is). 我的问题是我不知道如何访问对象的Arraylist(其中???)。 I want to loop through them out to determine the most northerly point. 我想循环遍历它们以确定最偏向的点。

Any help would be appreciated. 任何帮助,将不胜感激。

Just use this : 只要用this

for (Place curPlace : this)
{
}

I would personally avoid extending ArrayList<Place> to start with though - I prefer to use composition over inheritance, so I would normally make my class contain a List<Place> instead. 我个人会避免扩展ArrayList<Place>来开始 - 我更喜欢使用组合而不是继承,所以我通常会让我的类包含 List<Place>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM