0

The goal is to call a function with all elements from a stream of stream.

The issues I have is more complicated, but I manage to reproduce with this simple code.

With the following code, I get this error:

 Type mismatch: cannot convert from Stream<Object> to Stream<Integer>



    import java.util.List;
    import java.util.stream.Stream;

    class Ideone
    {
        public class A {
            String a = "a";
            List<B> bList;
        }


        public class B {
            String b = "b";
            List<String> urls;
        }


        public Stream<Integer> getResult (String a, String b, String url) {
            System.out.println("Bingo!");
            return Stream.empty();
        }



        public static void main (String[] args) throws java.lang.Exception
        {
            A a = new A();
           Stream<Integer> rez = a.bList.stream().map(b -> b.urls.stream().map(u -> getResult(a.a, b.b, u)));
        }
    }
1
  • Solution: Stream<Integer> rez = a.bList.stream().flatMap(b -> b.urls.stream().flatMap(u -> getResult(a.a, b.b, u))); Commented Jan 26, 2017 at 23:31

1 Answer 1

2

Replace

a.bList.stream().map(...)

with

a.bList.stream().flatMap(...)
Sign up to request clarification or add additional context in comments.

1 Comment

care to elaborate?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.