KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to implement a Singleton with Java enum. But I also want to pass some parameters to the constructor when it is initialized for the first time. How do I achieve that? Is it a good practice to have Singletons with parameter? public enum DaoManager { INSTANCE; private static ILog logger; //for passing the logger; private static DatabasePool pool; //passing the Database pool public void init(ILog logger, DatabasePool pool){ this.logger = logger; this.pool = pool; } } Right now I am using a init method to pass the logger and database pool to DaoManager. But if client fails to invoke the init() method then there a good chance of failure. Can someone please guide me on how do I do this?
Tags (comma-separated)
Save Edits
Cancel