Forum Stats

  • 3,722,791 Users
  • 2,244,415 Discussions
  • 7,850,094 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Lesson 3. Slides 3-6 (Debugging)

50123441-6d07-4a06-bc00-b4430c14da9b
edited December 2016 in Java Lambda MOOC

.peek(s -> s)

This code does not compile.

java: incompatible types: bad return type in lambda expression

    missing return value

How I can add Consumer that does nothing to method peek() for debugging?

Tagged:
50123441-6d07-4a06-bc00-b4430c14da9b

Best Answer

  • eudriscabrera-JavaNet
    eudriscabrera-JavaNet Member Posts: 214 Bronze Badge
    edited December 2016 Accepted Answer

    A simple example :

    List<String> list = Arrays.asList(

            "BarCamp", "MongoDB", "10Gen", "TokuMX", "Nagios", "PUCMM", "Ruby", "JSON", "JSON");

    List<String> newList1 = list

                .stream()

                .filter(s -> (s.length() % 2)==1)

                .map(String::toLowerCase)

                .peek(System.out::println)

                .collect(Collectors.toList());

    Output:

    barcamp

    mongodb

    10gen

    pucmm

    You can use the peek method to put a breakpoint while you are debugging with your favorite IDE.

    List<String> newList1 = list

                .stream()

                .filter(s -> (s.length() % 2)==1)

                .map(String::toLowerCase)

                .peek(s -> s.toString())

                .collect(Collectors.toList());

    The breakpoint must be set in the peek method.

    50123441-6d07-4a06-bc00-b4430c14da9b

Answers

  • eudriscabrera-JavaNet
    eudriscabrera-JavaNet Member Posts: 214 Bronze Badge
    edited December 2016 Accepted Answer

    A simple example :

    List<String> list = Arrays.asList(

            "BarCamp", "MongoDB", "10Gen", "TokuMX", "Nagios", "PUCMM", "Ruby", "JSON", "JSON");

    List<String> newList1 = list

                .stream()

                .filter(s -> (s.length() % 2)==1)

                .map(String::toLowerCase)

                .peek(System.out::println)

                .collect(Collectors.toList());

    Output:

    barcamp

    mongodb

    10gen

    pucmm

    You can use the peek method to put a breakpoint while you are debugging with your favorite IDE.

    List<String> newList1 = list

                .stream()

                .filter(s -> (s.length() % 2)==1)

                .map(String::toLowerCase)

                .peek(s -> s.toString())

                .collect(Collectors.toList());

    The breakpoint must be set in the peek method.

    50123441-6d07-4a06-bc00-b4430c14da9b
Sign In or Register to comment.