constructor - Java: What is the difference between these methods of construction -


What is the difference between the two methods of supervising the ArrayList, or is there any other kind of comparison for that matter Is fast in Or I'm missing out on some other benefits here

class publisher executes (Personal Array List Supervisor = New Arrielist); } Class Publisher Observer (Private Arrested Supervisor; Public Publisher () {Supervisor = New Array List); }}

They are identical, in fact, if you compile two you will see That they generate the same byte code:

  publisher (); Code: 0: Aloud_0 1: Innovative # 1; // method java / lang / object "& Lt; init & gt;" :() V4: Aldaudy 5: new # 2; // Class Java / Usage / Arrayist 8: dup 9: Inventions # 3; // Method Java / Usage / Array List. "& Lt; init & gt;" :() V12: Puddfeld # 4; // field supervisors: Ljava / util / ArrayList; 15: Return}  

Given that they are the same code, clearly there can be no speed difference :)

Note that C # They are not quite equal in - initializer before base constructor calls in C # to supervisor ; They are exactly the same in java.

What you use is a matter of taste. If you have many different constructors, all of which initialize the variable in the same way, then it can be understood to use the first form. On the other hand, this is usually a good idea if you have many constructors, then try calling most of them a "core" constructor who works real.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -