Error
The method toMap(Function<? super T,? extends K>, Function<? super T,? extends U>) in the type Collectors is not applicable for the arguments ((<no type> p) -> (Integer) p)
Error Type
Compile Time ( Java 8 )
Sample Code
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect((Collectors.toMap(p->(Integer)p))));
Cause
The method Collectors.toMap here expects two lambda expression arguments - One for Key and another for Value.
Possible Resolution
Specify two lambda expression arguments for Key and Value.
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect((Collectors.toMap(p->(Integer)p,q->((Integer)q)*500))));
The method toMap(Function<? super T,? extends K>, Function<? super T,? extends U>) in the type Collectors is not applicable for the arguments ((<no type> p) -> (Integer) p)
Error Type
Compile Time ( Java 8 )
Sample Code
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect((Collectors.toMap(p->(Integer)p))));
Cause
The method Collectors.toMap here expects two lambda expression arguments - One for Key and another for Value.
Possible Resolution
Specify two lambda expression arguments for Key and Value.
Set<Integer> intSet = new HashSet<Integer>();
intSet.add(1);
intSet.add(2);
intSet.add(3);
intSet.add(4);
System.out.println(intSet.stream().collect((Collectors.toMap(p->(Integer)p,q->((Integer)q)*500))));