How to avoid code repetition initializing final properties?

Posted by Hernán Eche on Stack Overflow See other posts from Stack Overflow or by Hernán Eche
Published on 2010-03-31T19:25:20Z Indexed on 2010/03/31 19:33 UTC
Read the original article Hit count: 481

Filed under:
|
|
public class Code{

//many properties
//...

final String NEWLINE;// ohh a final property!

void creation() //this method is for avoid repetition of code
{        

    //final initialization can't be put here =(

    Source= new StringBuffer();

   //many other commons new's ..
   //...
}

Code()
{
    NEWLINE = System.getProperty("line.separator");
    creation();
}

Code(String name, int numberr)
{
    NEWLINE = System.getProperty("line.separator");
    creation();

    name=new Someting(name);
    number = new Magic(number);
}

}

© Stack Overflow or respective owner

Related posts about java

Related posts about final