Code to execute the static method:
Method method = Utils.class.getMethod("generateCacheFolderName", Integer.class); System.out.println(method.invoke(null, new Integer(10)));
and class with static method:
public class Utils { public static String generateCacheFolderName(Integer len) { Random rand = new Random(); StringBuilder sb = new StringBuilder(len); for(int i = 0; i<len; ++i) sb.append(rand.nextInt() % 10); return sb.toString(); } public static String otherStaticMethod() { return null; } }
source share