Forum Stats

  • 3,723,348 Users
  • 2,244,533 Discussions
  • 7,850,425 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BiFunction reference from a string representing classpath of the function (method)

Stan Hughes
Stan Hughes Member Posts: 21 Blue Ribbon

I am trying to figure out how I can use a string containing the classpath of a method to create a Bifunction reference I can use in a lambda. I may be going about this all wrong - but...

For instance:

If I had the following class:

package com;

public class Greeter {

  public String helloWorld(String firstname,String lastName) {

      return "Hello, "+firstname+" "+lastname;

  }

}

How could I create a Bifunction reference from a string so that I could put it into a hashtable:

Hashtable<String,BiFunction<String,String,String>> functions = new Hashtable<>();

ReferenceToBiFunction ref = GetReferenceToBiFunctionFromString("com.Greeter::helloWorld");

functions.put("HelloWorld",ref);

Is there a way to do this?

Sign In or Register to comment.