3 ms·
I was quite amazed by IntelliJ's refactoring capabilities just few days back. I had code like below switch(sort) { case "asc": sortedComments =
by krisgenre 6y ago
I was quite amazed by IntelliJ's refactoring capabilities just few days back. I had code like below
switch(sort) {
case "asc":
sortedComments = topicComments
.stream().map(Comment::getThreadComments).filter(Objects::nonNull).flatMap(Collection::stream)
.sorted(Comparator.comparingLong(PostResponse::getCommentPostedTimeMilles)).collect(Collectors.toList());
break;
case "desc":
sortedComments = topicComments
.stream().map(Comment::getThreadComments).filter(Objects::nonNull).flatMap(Collection::stream)
.sorted(Comparator.comparingLong(PostResponse::getCommentPostedTimeMilles).reversed()).collect(Collectors.toList());
break;
}
I selected the first case and applied "Extract to method" and IntelliJ automatically suggested and applied the method to the second case also. Not sure if Eclipse will do that.
- vbezhenar 6y agoSometimes Idea finds duplicated code without your interaction and suggests to extract it into method. I don't always like it, but it's an interesting feature.
- phist_mcgee 6y agoI find sometimes duplicated code is from a business domain quite separate from another, yet intellij wants to bring them together. Sure, one day I will get my shit together on that duplicated code and fix the issue, but sometimes the hassle is not worth the hours put in to refactor. Nice that intellij lets you know though.