Home > Back-end > Without a new object instance method calls itself
Without a new object instance method calls itself
Time:02-05
@ Service (" Service ") Public class ServiceImpl implements Service {
The @autowired Private Mapper Mapper.
@ Override Public Tsysdic get (Integer Id) { Mapper. The select (Id); } @ Override Public void the delete (Integer Id) { //call the get method, I thought that I have to inject the Service, and then the method, feel a little uncomfortable, I'm new ServiceImpl (), to get the object, then go to invoke the get method, program error, mapper. Select (Id) this error null pointer //solution is can directly call get Get (Id); } } The instance methods get (), why can be called directly, should be static to direct call, where I messed up, please answer
CodePudding user response:
You are right, but the get (Id), is this. Get (Id), said this is the current object, so for all the ordinary method of a class, can call each other between ordinary method, I hope it can help you!
CodePudding user response:
What you mean? Invoke the get method is not called public Tsysdic get (Integer Id) this method? The delete method is not static, why can't directly call the get method, if the delete is the static method, it only need a get is static can invoke (namely static method cannot directly call non-static methods, but now is, delete and get is not a static method, so there is no problem you said)