• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initiaizing the reference varibles

 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though I am not in any mood to start controversy here but looking for the best way to initialize the variables when we don't have the values to be assigned at run time.
In this situation, I can either initialize reference variables to Null, empty or left them uninitialized.


Though local and final variables will give compilation errors if left uninitialized so they have to be either empty or null initialized.

What is you call on the following ways of initializing variables. And how to handle erroneous conditions in a program regarding these initializations. Is it good to place null checks or checks for empty initializations.

;
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean only local variables?

What do you mean by reference variables? Do you mean fields? What does Null, empty or ... uninitialised mean?

If you have values which are uninitialised at runtime, why do you have those variables in the first place? If you have a final field which you are initialising to null, that looks like poor design to me. Get rid of whichever constructor initialises those values to null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic