Mentor says:
1. The newArrayList method must return an ArrayList.
2. The newHashSet method must return a HashSet.
3. The newHashMap method must return a HashMap.
I think I return them, so what's wrong in my code?
package com.codegym.task.task35.task3509;
import java.util.*;
/*
Collections & Generics
*/
public class Solution {
public static void main(String[] args) {
}
public static <T> ArrayList newArrayList(Object... elements) {
ArrayList<T> arrayList = new ArrayList();
for(Object o : elements){
arrayList.add((T) o);
}
return arrayList;
}
public static <T> HashSet newHashSet(Object... elements) {
HashSet arrayList = new HashSet();
for(Object o : elements){
arrayList.add(o);
}
return arrayList;
}
public static <K, V> HashMap newHashMap(List<K> keys, List<V> values) {
if(keys.size()!=values.size()) {
throw new IllegalArgumentException();
}
HashMap<Object, Object> map = new HashMap();
for (int i=0; i<keys.size(); i++) {
map.put(keys.get(i), values.get(i));
}
return map;
}
}