Dav*_*vid 5 c# java abstract-class field interface
public interface IHashStorage<T> {
public static final float INITIAL_LOAD_FACTOR = 0.7f;
public static final int INITIAL_CAPACITY = 149;
}
Run Code Online (Sandbox Code Playgroud)
我有上面的代码需要在c#中翻译.唯一合适的解决方案是使它成为一个抽象类.从我发现使用readonly比使用const更安全:
public abstract class IHashStorage<T>
{
private readonly float INITIAL_LOAD_FACTOR = (float)0.7;
private readonly int INITIAL_CAPACITY = 149;
}
Run Code Online (Sandbox Code Playgroud)
Java中的项目使用了Decorator模式和Proxy,从java到c#的转换可能需要使用更抽象的类(目前在java中只有接口使用)?我从理论上讲它们之间的区别但实际上在c#中我使用过抽象类更多.我不熟悉java,我想知道你如何找到完成这个任务的最佳解决方案,我的意思是转换代码时要记住的要点.