Search code examples
javavb.netjava-8actionconsumer

How to write an Action function with two parameter in java


I have below function written in VB.Net, Is there a way to convert this to Java. I tried Consumer() but it only accepts one parameter.

Dim setFunc 
As Action(Of String, Object) = Sub(name, val) 
                               Console.WriteLine
                               ("Test Function. Name: {0}, Value: {1}", name, val)

Solution

  • Have you tried this

    BiConsumer<String, Object> setFunc = 
          (x, y) -> System.out.println("Test Function. Name : " + x + ", Value " + y);