开发者社区 问答 正文

livewallpaper中关于list的疑问

代码中有个MyPoint类
screenshot
然后又创建了一个MyWallpaperService类。这个类里面有一个像这样的代码行
screenshot
代码的部分还有这么一句
screenshot
这就是我不明白的地方。List会在circles传递什么?这个list列表要加载到一个类吗?有谁知道这个类是调用什么函数呢?

展开
收起
蛮大人123 2016-02-15 12:05:17 2008 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    private List<MyPoint> circles;
    申明 circles 是一个 MyPoint 类型的列表。
    circles = new ArrayList<MyPoint>();
    上面这一行把 MyPoint 类型的 ArrayList 对象分配给 List 类型中的 Reference 对象变量。
    这被称为 Interface Polymorphism。
    List是一个接口,作为 ArrayList 一个具体的类,来实现列表。

    public class Dog{
    
       private String dName;
       priavet int dAge;
    
       public Dog(String dName, String dAge){
    
          this.dName = dName;
          this.dAge = dAge;
       }
    
       public String getDName(){
    
            return this.dName;
       }
       public String getDName(){
    
            return this.dAge;
       }
    }
    
    public class Test{
    
    
     public static void main(String[] args){
    
         List<Dog> dAList = new ArrayList<Dog>();
    
         dAList.add(new Dog("Tommy",5));
         dAList.add(new Dog("Stark",2));
    
         for(Dog d : dAList){   // Iterating over the List of Dog objects
    
               System.out.println(d.getDName());
               System.out.println(d.getDAge());
    
             }
         }
    }
    2019-07-17 18:43:09
    赞同 展开评论
问答地址: