Я хочу прикрепить публичный метод к классу.Это называется метод расширения в C # .
package extensionMethods
class A {
def testA() {}
//def testB() {} Need to add a public method to this class A but we don't have access to the class
}
class B {
def test() {
def a = new A();
a.testA()
a.testB() //Need to add a public method to the Class A without defining the method in the class A
}
}
//In C# way -> Extension method
class C {
/* void testB(this A a) {
}*/
}
Как мы можем добиться аналогичного подхода в Groovy?В приведенном выше примере я хочу присоединить метод testB()
к class A