fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static <K, V, T extends Collection<V>> boolean addToGroupMap(K key, V value, Map<K, T> checkMap){
  11. assert checkMap!=null;
  12. boolean result = false;
  13.  
  14. Collection<V> vList = checkMap.get(key);
  15. if (vList==null){
  16. checkMap.put(key, new T(Collections.singleton(value)));
  17. }else {
  18. vList.add(value);
  19. result = true;
  20. }
  21. return result;
  22. }
  23.  
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. // your code goes here
  27. }
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:16: error: unexpected type
	        checkMap.put(key, new T(Collections.singleton(value)));
	                              ^
  required: class
  found:    type parameter T
  where T,K,V are type-variables:
    T extends Collection<V> declared in method <K,V,T>addToGroupMap(K,V,Map<K,T>)
    K extends Object declared in method <K,V,T>addToGroupMap(K,V,Map<K,T>)
    V extends Object declared in method <K,V,T>addToGroupMap(K,V,Map<K,T>)
1 error
stdout
Standard output is empty