【GitHub Copilot】GitHub Copilot的特点,同样的问题得到的答案可能不一样
2025年09月21日
文章浏览:57
【GitHub Copilot】GitHub Copilot的特点,同样的问题,生成的代码可能有差别,不同的人得到的答案可能不一样

我有如下注释


//YYYY/MM/DD形式の文字列をDate型に変換


第一次生成的代码如下

    //YYYY/MM/DD形式の文字列をDate型に変換
    public static Date parseDate(String dateString) {
        List<String> parts = dateString.split('/');
        if (parts.size() != 3) {
            throw new IllegalArgumentException('Invalid date format. Expected YYYY/MM/DD');
        }
        Integer year = Integer.valueOf(parts[0]);
        Integer month = Integer.valueOf(parts[1]);
        Integer day = Integer.valueOf(parts[2]);
        return Date.newInstance(year, month, day);
    }


第二成的代码如下

    //YYYY/MM/DD形式の文字列をDate型に変換
    public static Date parseDate(String dateString) {
        List<String> dateParts = dateString.split('/');
        if (dateParts.size() != 3) {
            throw new IllegalArgumentException('Invalid date format. Expected format: YYYY/MM/DD');
        }
        Integer year = Integer.valueOf(dateParts[0]);
        Integer month = Integer.valueOf(dateParts[1]);
        Integer day = Integer.valueOf(dateParts[2]);
        return Date.newInstance(year, month, day);
    }


大致看是差不多的代码,我们用WinMerge来比较一下。

就可以看到有细微的差别,这是GitHub Copilot,当然也包括ChatGPT,这是他们共同的特点之一。

同样的问题,可能得到的答案会不太一样。




关注 收藏