Is it possible to declare the final int field in the Service class and initialize it with some integer that I get from the database query in the onCreate () method?
public class MyService extends Service
{
private int id;
@Override
public void onCreate()
{
... calculate id value ...
id = <id value derived>;
}
}
I got this error in Eclipse inside the onCreate () method in the field assignment line:
"The final field cannot be id cannot be assigned"
and this error in the class definition line:
"The blank final field id may not have been inizialized"
As I understand it, this is the correct way to define the field that you want to initialize only once. Can someone help me? Thanks
source
share