So I have a generic class that I've created and I need to print it out to see if I am passing the correct values. Only when I print it I get
PointList@7852e922
I don't understand how I can print out the actual values. Everything I've read just helps with ArrayLists and not generic classes. I tried using stringbuilder and I tried writing a toString method in my PointList class and I keep getting errors. Am I on the right track using one of those two methods? Is there a way to print it out?
public class PointListTest{
public static void main(String[] args){
//create point ints
Point<Integer> pointOne = new Point<Integer>(1,2);
Point<Integer> pointTwo = new Point<Integer>(3,4);
Point<Integer> pointThree = new Point<Integer>(5,6);
//make object PointList pointlist for int
PointList<Point<Integer>> newPointList = new PointList<Point<Integer>>();
//add points to list
newPointList.add(pointOne);
newPointList.add(pointTwo);
newPointList.add(pointThree);
//print list
System.out.println(newPointList);
Here is the PointList class
public class PointList<E>{
private List<E> myList;
E data;
public PointList(E obj){
myList = new ArrayList<>();
data = obj;
}//end constructor
public PointList(){
myList = new ArrayList<>();
}//end no args constructor
public void add(E obj) {
myList.add(obj);
}
This is what I have in my toString method.
@Override
public String toString(){
return("" + data);
}//end toString
Point class has this toString method
@Override
public String toString(){
return (xCordinate + "," + yCordinate);
}//end toString