Campbell Ritchie wrote:The method reference is one way to pass a λ expression. Are you not familiar with method references? If you go through the Java™ Tutorials, you will find out that you are not passing the method (as you might in C), but that is part of the way you can define an object that uses that method.
Adding discussion to what used to be the Java8 forum.
Most probably yes. Let's start with something simpler that I can actually understand
Kevin Mckeon wrote:. . . Is there a way of doing this without using λ expression ? . . .
I can't see any multiline Strings in the current thread. There have been several attempts to write multiline text, I think in Java12/13, but I am not sure that the final version has been implemented yet.
kiros haregewoine wrote:Aside the lambda problem. The other issue is how to break multi-line string. There is new feature in java 11, I think.
Where is there an i missing ()?
In the above code, the int i should be inside bracket (int i)
Yes, you are right there. Sorry for my mistake. It would probably run happily without the type:- foo(i -> myUslessInstance.add(i)) The String#lines() method returns a Stream<String> handling the separate lines the String can be divided into (I got an empty Stream from an empty String).
kiros haregewoine wrote: . . .
foo(int i -> myUslessInstance.add(i))
should be changed to
for ((int i) ->myUselessInstance.add(i))