I have created a Consumer which takes a string and makes it uppercase. I am trying to implement it along with a map to make all the strings in a list to uppercase. I understand that this can be done easily using String::toUpperCase
but I am trying to do it with a Consumer and I am getting the following error
java: incompatible types: inferred type does not conform to upper bound(s)
inferred: void
upper bound(s): java.lang.Object
Here is my code
Consumer<String> upper = name -> name.toUpperCase();
names.stream().map(name -> upper.accept(name)).collect(Collectors.joining(" "))
I want to know if this is the correct way to use Consumer interface and also what would be a typical scenario where using Consumer would be helpful?