I have below interface and its implementation class.
Demo.java
public interface Demo{
void showDemo();
}
DemoImpl.java
@Service
public class DemoImpl implements Demo{
public void showDemo(){
//To Do
}
}
Now i have one class with static method which will internally call showDemo() as below.
DemoStatic.java
@Component
public class DemoStatic{
@Autowired
private Demo demo;
public static void callShowDemo(){
demo.showDemo(); //calling non static method from static method
}
}
Here i am calling non static method from static method. Is my design correct? Or do i need to change my design? Please suggest me.
Thanks!
解决方案
No your design is not correct.
private Demo demo;
has to be
private static Demo demo;
You just cant use NON static members in a static method