Discuss / Java / 修复

修复

Topic source

alienation

#1 Created at ... [Delete] [Delete and Lock User]

把浅拷贝过程留在构造方法里,不让外部接触到

class Score {
    private int[] scores;
    public Score(int[] scores) {
        int[] tmp = new int[scores.length];
        for (int i=0;i<scores.length;i++) {
            tmp[i] = scores[i];
        }
        this.scores = tmp;
    }

🌙

#2 Created at ... [Delete] [Delete and Lock User]

借楼,作业思路,就是.复制另一份出来


  • 1

Reply