Java Optimizations

前端 未结 5 1764
忘了有多久
忘了有多久 2021-01-24 04:38

I am wondering if there is any performance differences between

  1. String s = someObject.toString(); System.out.println(s);

    and

  2. System.out.pr

5条回答
  •  借酒劲吻你
    2021-01-24 05:32

    There is no* code critical enough that the difference between your two samples makes any difference at all. I encourage you to test this; run both a few million times, and record the time taken.

    Pick the more readable and maintainable form.

    * Exaggerating for effect. If you have code critical enough, you've studied it to learn this.

提交回复
热议问题