我面对Java中的示例代码,它给我带来了一个问题.
Java示例代码是:
...
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
void printf(String format, Object... args);
}
public static void main(String[] args) throws IOException {
CLibrary.INSTANCE.printf("Hello, World\n");
}
Run Code Online (Sandbox Code Playgroud)
但是在C#中我们不能这样写:
public interface IMyInterface {
static readonly int staticInt = 5; // compile error
static readonly SomeClass staticInstance = new SomeClass(); // compile error
}
Run Code Online (Sandbox Code Playgroud)
这两种语言/框架有什么区别?
什么设计策略允许java在接口中使用const字段或什么阻止.NET拥有它?