jeudi 5 août 2021

How to implement a java plugin library where you can search methods by signature

I was asked this question during an interview and could not come up with a good solution. Basically, I have to implement a java library where clients can register there methods and later search for methods by their signature.

Below is the Function class --

class Function {
  public final List<String> argumentTypes; // e.g. ["Integer", "String", "PersonClass"]
  public final String name;

  Function(String name, List<String> argumentTypes) {
    this.name = name;
    this.argumentTypes = argumentTypes;
  }

  public String toString() {
    return this.name;
  }
}

The above class cannot be changed. And then I have this skeleton code --

 class FunctionLibrary {
     void register(Set<Function> functions) {
      
      }
      List<Function> findMatches(List<String> argumentTypes) {
    
        return null;
      }
}








    
    
         

What should be the implementation of the findMatches and register methods ?

Aucun commentaire:

Enregistrer un commentaire