-2

Ok here is same question why database name must be static? but i know already that why we should declare database name static & final.

And i tried to give non static database name into constructor of SQLiteOpenHelper but end up with an error the field can't be quoted from the static context

I want to know/find the source code or particular line where it was decided to make those ( database & version ) static.

I looked already https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/database/sqlite/SQLiteOpenHelper.java but couldn't find.

laalto
  • 150,114
  • 66
  • 286
  • 303
Golu
  • 350
  • 2
  • 14

1 Answers1

1

It's about Java, not about Android sqlite.

When initialising an object instance, constructor is invoked before initialising member fields. The database name is a constructor argument and needs to be initialised when invoking the constructor. When it's static, it's not an instance member but a class member that is initialised earlier when the class is first accessed.

See Java order of Initialization and Instantiation

laalto
  • 150,114
  • 66
  • 286
  • 303