What does the 'new' keyword actually do in Java, and should I avoid creating new objects?

前端 未结 6 1349
盖世英雄少女心
盖世英雄少女心 2020-11-28 10:15

I signed up a few moments ago, though I\'ve been making great use of this site since I took up computer programming, which I\'ve been teaching myself and consider a little h

6条回答
  •  天涯浪人
    2020-11-28 11:06

    A new object is created every time the method is called. If control reaches a line of code with a "new" operator on it, then an object is going to be created; there's no behind the scenes caching or other magic.

提交回复
热议问题