Menu

#1404 Java8 'Unnecessary use of fully qualified name' in Streams Collector

PMD-5.3.4
closed
PMD
3-Major
Bug
5.3.2
2015-09-16
2015-09-14
Pedro Rijo
No

I'm using PMD for analyse a Java 8 project and I'me getting an unexpected result.

In one method I have a Stream s:

s.collect(Collectors.toList());

and I receive an error: Unnecessary use of fully qualified name 'Collectors.toList' due to existing import 'java.util.stream.Collectors', but as far as I have tested, it is not possible to not include the Collectors prefix.

The code is available at https://github.com/FenixEdu/fenixedu-learning/blob/master/src/main/java/org/fenixedu/learning/domain/executionCourse/components/InitialPageComponent.java#L50

Discussion

  • Andreas Dangel

    Andreas Dangel - 2015-09-16
    • status: open --> wont-fix
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.4
     
  • Andreas Dangel

    Andreas Dangel - 2015-09-16

    Hi,
    that's actually correct - you have also a static import of Collectors.toList() which means you can call "toList" directly without the class name...

    However, the message is not entirely clear about this... it should better say "... due to existing static import 'java.util.stream.Collectors.toList".

    I'll change the message to be:

    Unnecessary use of fully qualified name 'Collectors.toList' due to existing static import 'java.util.stream.Collectors.toList'
    

    Thanks,
    Andreas

     
  • Andreas Dangel

    Andreas Dangel - 2015-09-16
    • status: wont-fix --> closed
     
  • Pedro Rijo

    Pedro Rijo - 2015-09-16

    Was not aware of that. Thanks, and sorry.

     

Log in to post a comment.

MongoDB Logo MongoDB