I’m looking at some lwjgl’s tutorials and occurred to me instead of keeping the class instantiated in a variable, instantiate it and call the method directly without saving the object.
I was wondering if it’s good to do this when you don’t have to reuse the object later, or whether it is best to always keep the object.
I mean this:
(new Lesson02()).run(fullscreen);
instead it:
Lesson02 l2 = new Lesson02();
l2.run(fullscreen);
Thanks.
There is not really any difference if you do not plan to use the object later. So option 1 is fine. If you follow option 2 and end up not using
l2later in the code then it will get garbage collected anyway.