在JavaScript中,可以按照以下步骤进行操作:
var qwerty = (function() {
//some code
return returnValue;
}
Run Code Online (Sandbox Code Playgroud)
这将分配的returnValue到QWERTY键盘。有没有办法用Java做类似的事情?就像是:
int num = {
public int method() {
//some code
return val;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以写出一个单独的方法,但是我想以与上面类似的方式来做,因为它在我编写的代码中看起来更加整洁。