안드로이드 개발 질문/답변
(글 수 45,052)
Avoid Creating Unnecessary Objects
- If you have a method returning a string, and you know that its result will always be appended to a StringBuffer anyway, change your signature and implementation so that the function does the append directly, instead of creating a short-lived temporary object.
- When extracting strings from a set of input data, try to return a substring of the original data, instead of creating a copy. You will create a new String object, but it will share the char[] with the data. (The trade-off being that if you're only using a small part of the original input, you'll be keeping it all around in memory anyway if you go this route.
와 같이 게시되어있습니다. 즉 위의 처음에서는 객체를 생성하지 말고 그냥 함수가 직접적으로 하라고 하는데...
c++ 에서는 참조로 전달할 경우에는 새로운 객체를 만들지 않고 리턴하게 됩니다.. 하지만 여기서는 무엇을 의미하나요?
질문 2. 새로운 복사본을 만들지 말고, 그냥 substring을 리턴하라.
어차피 새로운 복사본을 만들건, substring을 리턴하건.. 새로운 객체가 생성되는 것은 마찬가지 아닌가요?



