chenggwang commented on PR #671:
URL: https://github.com/apache/tomcat/pull/671#issuecomment-1763120686

   > I do not like the use of "?:" operator here. Just simple `... + ":" + sc;` 
is enough, or if you want to be explicit `+ ":" + String.valueOf(sc);`
   
   If we don't consider the constant pool memory consumption, and readability 
(String + Object, which doesn't clearly express the intent). Your method is 
fine this way. In fact this will end up with one more entry in the constant 
pool. like this
   `#1 = Methodref          #xx.#xxx     // 
java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;`
   `#2 = Methodref          #xx.#xxx      // 
java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;`
   
   `super.toString() + sc`, the first one is a string, the second one is an 
object,So two entries are needed.If they are all strings, only entry #1 is 
needed.Strong transfer object type, not recommended for + reasons . This is 
just a lazy approach.Avoid this if there are a lot of character operations in a 
lot of classes (message middleware, logging systems, etc.), memory is also 
precious!
   As for String.valueOf(sc), sc can't be null, direct NPE, not to mention it's 
a series of method stack calls, less efficient.
   Thank you for your input. The main discussion is about the need to ensure 
that toString() is available to the public immediately after the object is 
created, and I'm encountering NPEs caused by it in my project that monitors 
object lifecycles and buries it, do you have any good ideas?@kkolinko
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to