ERROR - The method toMap(Function, Function) in the type Collectors is not applicable for the arguments (( p) -> (Integer) p)

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))));