Evaluate if a method exists


(Matty & Troy) #1

I’m trying to make sure that I can execute a method - eg setHue - before making that call.

I’ve tried respondsTo - but that doesn’t seem to work.


(Matty & Troy) #2

I’m using the below - i don’t think it is very elegant.

        	log.debug("Trying to set colour to $colour")
            try {
                thisSwitch.setHue(colourMap[colour]["hue"])
            } catch (Exception e) {
                log.debug "$thisSwitch does not support setHue"
            }