So I'm trying to create a simple program that allows for me to put an array of Int, String, double.... to an object and the print it:
public class Array<E> {
private E[] data;
private int size;
public Array(int size, E[] data)
{
this.size=size;
for(int i=0; i<size; i++) this.data[i]=data[i];
}
public String toString()
{
String s=new String();
for(int i=0; i<size; i++) s+=data[i]+" ";
return s;
}
}
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int A[]= {1, 3, 5, 7};
Array<Integer> niza=new Array<Integer>(4, A);
System.out.println(niza.toString());
}
}
However it gives me this error whenever I try to create the object:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The constructor Array(int, int[]) is undefined
at test.Main.main(Main.java:8)
Any ideas of what's causing the problem and a possible solution?
Thanks in advance!
Integer A[]= {1, 3, 5, 7};this.databeing null