W
www
Hi,
I want to have a static field variable. I want to initiate it once and
don't want it to be changed any more. So
public MyClass
{
public final static rootDir; //error: saying rootDir may not be
initialized
public MyClass(String dir)
{
rootDir =dir; //error: saying that I cannot assign to a final variable
}
...
public void doIt()
{
...
}
public static void main(String[] args)
{
String str = args[0];
MyClass class = new MyClass(str);
}
}
I thought final variable can be assigned value once and only once. And
this can be done inside constructor. Cited from this web page:
http://renaud.waldura.com/doc/java/final-keyword.shtml in Final Field part.
Thank you for your help.
I want to have a static field variable. I want to initiate it once and
don't want it to be changed any more. So
public MyClass
{
public final static rootDir; //error: saying rootDir may not be
initialized
public MyClass(String dir)
{
rootDir =dir; //error: saying that I cannot assign to a final variable
}
...
public void doIt()
{
...
}
public static void main(String[] args)
{
String str = args[0];
MyClass class = new MyClass(str);
}
}
I thought final variable can be assigned value once and only once. And
this can be done inside constructor. Cited from this web page:
http://renaud.waldura.com/doc/java/final-keyword.shtml in Final Field part.
Thank you for your help.