public class Point {メインクラス:
private int x;
private int y;
public Point(int x, int y){
this.x=x;
this.y=y;
}
@Override
public String toString() {
return "[x= "+this.x+", y= "+this.y+"]";
}
}
import java.util.ArrayList;Run:
public class Main {
public static void main(String[] args) {
ArrayList<アイテム>list = new ArrayListです<アイテム>()
{
private static final long serialVersionUID = 1L;
@Override
public String toString()
{
return super.toString();
}
};
list.add(new Point(2, 4));
list.add(new Point(1, 6));
list.add(new Point(5, 2));
list.add(new Point(3, 7));
list.add(new Point(8, 9));
System.out.println(list.toString());
}
}
[[x= 2, y= 4], [x= 1, y= 6], [x= 5, y= 2], [x= 3, y= 7], [x= 8, y= 9]]この例では、ArrayList はメソッド toString() Point クラスで宣言されます。メソッドを削除すると toString() Point クラスでは、
[Point@4a5f634c, Point@3c7038b9, Point@6b9c18ae, Point@55187eb3, Point@3b26456a]
Please disable your ad blocker and refresh the window to use this website.