Search code examples
springhibernatespring-bootspring-securityjpa-2.1

Java 8 Stream Map Collector Error - role cannot be resolved to a variable


I am new to spring security. I was trying to creating my first project using spring boot and spring security with the help of this tutorial

In UserServiceImpl file there is a function mapRolesToAuthorities, it takes Collection < Role > roles as a parameter.

Now the problem is, when I try to stream and map the roles like this

private Collection < ? extends GrantedAuthority > 
mapRolesToAuthorities(Collection < Role > roles) 
    {
    return roles.stream().map(role - > new 
    SimpleGrantedAuthority(role.getRolename()))           
    .collect(Collectors.toList());
    }

It shows error that

role cannot be resolved to a variable

.

enter image description here

How can I resolve this issue?


Solution

  • There is a typo with extra space in lambda operator:

    role - >
    

    should be

    role ->