Skip to content

Comment on How many lines of Java would this take?

Comments

    class ObjectUtil {
        static boolean hasMethod(Object obj, String... methodNames) {
            for(String methodName : methodNames)
                if(!hasMethod(obj, methodName))
                    return false;
            return true;
        }
        
        static boolean hasMethod(Object obj, String methodName) {
            for(Method method : obj.getClass().getMethods()) 
                if(method.getName().equals(methodName)) 
                    return true;
            return false;
        }
    }
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.