void () { Map<Integer, MyList2<? extends Number, CharSequence>> result = new HashMap<>(); for (CharSequence x : getList()) { result.computeIfAbsent(x.length(), k -> createMyList2()).add(x); } Map<Integer, ? extends MyList2<? extends Number, ? extends CharSequence>> map = result; System.out.println(map); }