Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

메소드 리팩토링 #2

Open
kwongiho opened this issue May 30, 2019 · 0 comments
Open

메소드 리팩토링 #2

kwongiho opened this issue May 30, 2019 · 0 comments

Comments

@kwongiho
Copy link

kwongiho commented May 30, 2019

  • rankDao == null 보단, Objects.isNull(rankDao); 사용을 권장드립니다.

  • return null 보단 Collections.emptyList() 를 권장드립니다.

  • String클래스 같은 경우는 final 클래스이기 때문에 +와 같은 연산자를 만나면 인스턴스 자체가 확장되지 못합니다.

  • 그렇기 때문에 서로 .concat()메소드를 불러서 서로를 연결하는데요

  • 이는 심각한 성능이슈를 발생시킵니다.

  • 여러 String값들을 연결하셔야 하면, StringBuffer 혹은 StringBuilder류를 추천드립니다.

사실 자바 1.5? 부터는 +연산을 StringBuilder로 컴파일러가 바꿔준다고 하는데요.
컴파일러에게 의존하는 것 보다는 자체적으로 사용하시는걸 추천드립니다.

  • 두개의 클래스의 차이점을 알고계신다면 더욱 좋을 것 같습니다.

  • 또한, for 보단 for-each류를 추천드립니다.

comparator를 사용해야 하는 경우라면 for을 추천드립니다.

public ArrayList<String[]> getRanks() {
if (rankDao == null) {
System.out.println("RankGetService에서 getRanks() 메소드의 rankDao가 null");
return null;
}
ArrayList<String[]> ranks = new ArrayList<>();
ArrayList<Rank> rankD = rankDao.getRanks();
for (int i = 0; i < rankD.size(); i++) {
String[] rank = new String[] { "" + rankD.get(i).getRanking(), rankD.get(i).getName(),
"" + rankD.get(i).getScore() };
ranks.add(rank);
}
return ranks;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant