我希望能够做到这样的事情:
def closure = {
def a // create new variable, but ONLY if not created yet
if (a == null) {
a = 0
}
a++
print a
}
closure() // prints 1
closure() // prints 2
closure() // prints 3, etc...
Run Code Online (Sandbox Code Playgroud)
我想在闭包中创建INSIDE变量,而不是在外部作用域中.
我有三个类,一个是超类.
class abstract Base {
public abstract String getV();
}
class A extends Base {
private String v;
@Value("${A.v}") public String getV() { return v; };
}
class B extends Base {
private String v;
@Value("${B.v}") public String getV() { return v; };
}
Run Code Online (Sandbox Code Playgroud)
有没有办法简化spring @Value注释的使用?我不想复制粘贴"v"字段声明和所有Base子节点的getter.到目前为止我得到的是:
class abstract Base {
protected String v;
public String getV() { return v; };
public abstract void setV(String v);
}
class A extends Base {
@Value("${A.v}") public String setV(String v) { this.v = v;}; …Run Code Online (Sandbox Code Playgroud)