The task specification is as follows: "Your task is to create Multiplicator that receives Folders with anything that can be copied (i.e. implementing Copy interface) and creates an array of Folders with copies of the original Folder content."
I am trying to figure out how to add objects into the array. However, when I run the code that I have written, I get an output of null.
How can I add generic objects into an array?
import java.util.ArrayList;
import java.util.List;
/**
* Class to work with
*/
class Multiplicator {
public static <T extends Copy<T>> Folder<T>[] multiply(Folder<T> folder, int arraySize) {
// Method to implement
Folder myFolder = new Folder();
Folder<T>[] folderArray = new Folder[arraySize];
for (int i = 0; i < arraySize; i++) {
folderArray[i] = (Folder<T>) myFolder.get();
}
return folderArray;
}
public static void main(String[] args) {
System.out.println("Well done!");
}
}
// Don't change the code below
interface Copy<T> {
T copy();
}
class Folder<T> {
private T item;
public void put(T item) {
this.item = item;
}
public T get() {
return this.item;
}
}