Is it better to create a new object and return it or create the new object in the return statement?

后端 未结 6 1948
盖世英雄少女心
盖世英雄少女心 2021-01-05 12:24

For example:

public Person newPerson() {
  Person p = new Person(\"Bob\", \"Smith\", 1112223333);
  return p;
}

as opposed to:

<         


        
6条回答
  •  心在旅途
    2021-01-05 12:57

    No one is not more efficient than the other, the JIT will inline it out to the most efficient at runtime.

提交回复
热议问题