I have a static class, with all methods and fields static. My methods in that class are going to use a static field declared in that class.

I want that static variable(which can not be made final) to be initialized with a value taken from a database when that static class is accessed for the first time. And this variable should not be initialized later on in any case.

Recommended Answers

All 2 Replies

By using a Static Initialization Block.
Just check this tutorial

By using a Static Initialization Block.
Just check this tutorial

Oh yeah....how did I forgot this, its so stupid of me...Thanks buddy :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.