【发布时间】:2019-03-11 15:21:10
【问题描述】:
我是 Scala 的新手,我一直坚持创建一个对象并将其添加到 Scala 中的对象列表中。我想在scala中做下面的java实现。请提出合适的方法。
class Foo {
private int x;
private int y;
public Foo(int x, int y){
this.x = x;
this.y = y;
}
public int getX(){
return x;
}
public void setX(int x){
this.x = x;
}
public int getY(){
return y;
}
public void setY(int y){
this.y = y;
}
}
class Main {
List<Foo> fooList = new ArrayList<>();
Foo foo = new Foo(1,2);
fooList.add(foo);
}
【问题讨论】:
-
到目前为止有什么尝试吗?
-
@Andronicus 不,我不知道从哪里开始。我在 scala 中创建了一个类。
-
查看
List的文档,尤其是示例。简介应该够了scala-lang.org/api/2.12.3/scala/collection/immutable/List.html