在方法中声明本地内部类时,为什么包含最终的静态字符串或整数是合法的,但包含其他对象却不合法?
例如:
class Outer {
void aMethod() {
class Inner {
final static String name = "compiles";
final static int ctr = 10; // compiles
final static Integer intThree = Integer.valueOf(3); // does not compile!
final static obj objConst = new Object(); // does not compile!
}
Inner inner = new Inner();
}
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,我得到以下内容:
InnerExample.java:6: inner classes cannot have static declarations
final static Integer outer = Integer.valueOf(3);
^
InnerExample.java:7: inner classes cannot have static declarations
final static Object objConst …Run Code Online (Sandbox Code Playgroud) 我正在编写 clojure cli,想知道是否有办法测试输出(即 println)是写入控制台还是通过管道传输到另一个程序?
这与this question类似,但对于clojure。