如果我使用相同的声明和API将Java代码转换或重新实现为kotlin是否非法?

时间:2019-04-21 09:35:05

标签: java kotlin

例如,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许可证?

1 个答案:

答案 0 :(得分:0)

也许没有人关心这个法律意见,但是我认为这对于决定某些技术问题很重要。
到目前为止,我有一个我认为是正确的答案。
https://qr.ae/TWpiQ2