Translate

Wednesday 6 October 2021

MetaProgramming Customizing the MOP in Groovy Scripting groovy training telugu 44

 Watch This Video

https://youtu.be/AIyNehq684s


------------------------------------------------------------------------------------------------------------------
//InvokeDemo.groovy

package therealdnvega

//this method is called when the method you called is not present in the groovy


class InvokeDemo{

def invokeMethod(String name,Object args){

return"called invokeMethod $name $args"

}

def test(){

return "method exists"

}
}
def invokeDemo = new InvokeDemo()
assert invokeDemo.test()=="method exists"
assert invokeDemo.someMethod()=="called invokeMEthod someMethod[]"

//GetPropertyDemo.groovy

package therealdnvega

class PropertyDemo{

def prop1="prop1"
def prop2="prop2"
def prop3="prop3"
def getProperty(String name){
println "getProperty() called with argumeny $name"
// return

if(metaClass.getProperty(this,name)){
return metaClass.getProperty(this,name)
}
else{
println "less do something fun with this property"
return "party time....
}
}
}
def pd=new PropertyDemo()
println pd.prop1
println pd.prop2
println pd.prop3
println pd.prop4


No comments:

Post a Comment

Note: only a member of this blog may post a comment.