implementing interfaces in groovy
interface X {
void f();
void g(int n);
void h(String s, int n);
}
x = {Object[] args -> println "method called with $args"} as X
x.f()
x.g(5)
x.h("a string",2)
-----------------------------
interface X {
void f();
void g(int n);
void h(String s, int n);
}
x = [ f: {println "f is called"},
g: {int i-> println "g is called with param ${i}"},
h: {Object[] args -> println "h is called with ${args}"} ] as X
x.f()
x.g(5)
x.h("a string",2)
Comments
Post a Comment