passing java method as an argument or create a method local variable -


please @ option-1 , option-2 below.

i have experienced people telling me option-1 best , recommended way go improves readability. also, helps in knowing variable value during debug session.

however, option-2 removes following possibilities:

  • avoids unnecessary local variable creation , additional line of code
  • accidental altering of object state can call t.somemethod(..) alter state of object t
  • accidental assignment of t instance of entity (of course can avoided using final key word on variable t declaration).

please let me know accepted way out of this.


option-1:

public void method() {    entity t = method1();    method2(t); } 

option-2:

public void method() {    method2(method1()); } 


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -