例如,Java类java.io.File
的源代码为:
public class File
implements Serializable, Comparable<File>
{
/* -- Constructors -- */
/**
* Internal constructor for already-normalized pathname strings.
*/
private File(String pathname, int prefixLength) {
this.path = pathname;
this.prefixLength = prefixLength;
}
/**
* Internal constructor for already-normalized pathname strings.
* The parameter order is used to disambiguate this method from the
* public(File, String) constructor.
*/
private File(String child, File parent) {
assert parent.path != null;
assert (!parent.path.equals(""));
this.path = fs.resolve(parent.path, child);
this.prefixLength = parent.prefixLength;
}
public boolean createNewFile() throws IOException {
SecurityManager security = System.getSecurityManager();
if (security != null) security.checkWrite(path);
if (isInvalid()) {
throw new IOException("Invalid file path");
}
return fs.createFileExclusively(path);
}
public boolean delete() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkDelete(path);
}
if (isInvalid()) {
return false;
}
return fs.delete(this);
}
}
如果我将这些代码转换为kotlin,无论使用IntelliJ IDEA复制粘贴转换功能,还是手动重新实现,然后重写一些内部实现。
可能看起来像这样:
open class File : Serializable, Comparable<File> {
/* -- Constructors -- */
/**
* Internal constructor for already-normalized pathname strings.
*/
private constructor(pathname: String, prefixLength: Int) {
this.path = pathname
this.prefixLength = prefixLength
}
/**
* Internal constructor for already-normalized pathname strings.
* The parameter order is used to disambiguate this method from the
* public(File, String) constructor.
*/
private constructor(child: String, parent: File) {
assert(parent.path != null)
assert(!parent.path.equals(""))
this.path = fs.resolve(parent.path, child)
this.prefixLength = parent.prefixLength
}
@Throws(IOException::class)
open fun createNewFile(): Boolean {
//My implementation code here...
}
open fun delete(): Boolean {
//My implementation code here...
}
}
假设它将在我的个人和商业应用程序中使用,是否违反了Oracle的JDK商业或GPLV2.0许可证?