Difference between Long.valueOf(java.lang.String) and new Long(java.lang.String)?

后端 未结 6 480
萌比男神i
萌比男神i 2020-12-24 13:13

I\'m consolidating code written by two different people and notice that casting a String value into a Long has been done in two different ways.

Coder #1 has done t

6条回答
  •  一整个雨季
    2020-12-24 14:02

    This is the PMD plugin out put which is run on eclipse

    Code I checked is

    Long l = new Long("123456");
    

    In JDK 1.5, calling new Long() causes memory allocation. Long.valueOf() is more memory friendly.

提交回复
热议问题