Skip to content
Advertisement

Void is not a functional interface

I am trying to subscribe observable like :

List<String> colors = Arrays.asList("RED", "BLACK", "WHITE", "GREEN", "YELLOW", "BROWN", "PURPUL", "BLUE");
    Observable.just(colors).subscribe(s -> System.out.println(s));

It’s working fine but if I use method reference compiler gives error “void is not a functional iterface”

Any one can explain little bit deep? As per me subscriber accept consumer functional interface, which doesn’t return anything but we can print stream data like :

 Observable.just(colors).subscribe(s -> System.out::println);// NOT COMPILE

Answer

Your method reference syntax is wrong. Change it like so,

Observable.just(colors).subscribe(System.out::println);
Advertisement