aspose file tools*
The moose likes Java in General and the fly likes Initiaizing the reference varibles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Initiaizing the reference varibles" Watch "Initiaizing the reference varibles" New topic
Author

Initiaizing the reference varibles

Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

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.

;


Java Experience
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Initiaizing the reference varibles