Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

set static final field after declaration?

807580Feb 18 2010 — edited Feb 20 2010
Hello,

I would like to declare a field as static final, yet set it later by a method after the method does some computation. Is there a way to do this?

If I:
static final int var;

public void my method(){

    calculate something...
    var = answer;
}
I get a compile time error.

I've done a lot of searching on this but haven't come up with anything yet.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 20 2010
Added on Feb 18 2010
14 comments
265 views