I am struggling with access to a member variable and not able to find any explanation for it. If I call app.initDB(config) , it works; however when i call initDB() as is , config is null. Please look into code snippet to locate problematic line.
I was expecting config to be initialised as i am invoking it for app object here.
public class App {
public RestConfig config;
public App(RestConfig config) {
config = config;
}
public void initDB() { // miss type returns
System.out.println(config); // <-- prints null , why?**
}
}
class RestMain {
public static void main(String[] args) throws IOException {
RestConfig config = new RestConfig();
App app = new App(config);
app.initDB();
}
}
public class RestConfig {
//some config...
}