以下兩個方法傳入參數類型不一樣,但是處理邏輯是一致的,要怎么才能消除重復代碼privatevoidsetStudentExamRank(Listlist){Listtemp=Lists.newArrayListWithCapacity(list.size());temp.addAll(list);temp.sort(Comparator.comparingInt(StudentExam::getScore));StudentExame;for(inti=0;i<temp.size();i++){e=temp.get(i);e.setRank(e.getScore()>0?i+1:0);}}privatevoidsetStudentClassesTestRank(Listlist){Listtemp=Lists.newArrayListWithCapacity(list.size());temp.addAll(list);temp.sort(Comparator.comparingInt(StudentClassesTest::getScore));StudentClassesTeste;for(inti=0;i<temp.size();i++){e=temp.get(i);e.setRank(e.getScore()>0?i+1:0);}}
怎么消除以下兩個方法的重復代碼?我做了嘗試,百度了也不行
函數式編程
2019-05-07 08:54:43