javastringtemplatestringtemplate-4

dynamically function call from String template


Is it possible to call a function of Java class through dynamically generated function from StringTemplate ?

for instance, following is a Java class with three functions

public class RegionManager {

    public static List<String> getCenter(){
       return somelist; 
    }   

    public static List<String> getFloor(){
         return somelist;   
    }

    public static List<String> getRoom(){
         return somelist;   
    }   

}

Now, my String template file contains $CS.name$ .. the value of could be "Room", "Floor", "Center".

based on the $CS.name$ value, I want to call function ( could be getRoom(), getFloor(), getCenter() ) . Please note that When I write String template file, I do not know , which function is going to be called.


Solution

  • You can't call static functions. You can only call getters on objects.