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)

CodePudding user response:

reference practice response: 1/f, called
you're 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!
mean, this has no explicit written out?

CodePudding user response:

refer to the second floor qybao response:
what 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, the only need to get is static to call (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
method is the instance method, can not have to call an instance object, can directly call it

CodePudding user response:

This call it must be have no questions, why think it has problem,

But that invoke the get method, if there is a spring section is invalid, because of this visit is not a proxy object, if you want to use a proxy object access, to dynamically access object to invoke from the beanFactory,

CodePudding user response:

You use spring, are you still in the new I would not say what, this get pulled up and static methods, then go to see a few times "se"

CodePudding user response:

reference 5 floor rumlee reply:
this call it must be have no questions, why think it has problem,

But that invoke the get method, if there is a spring section is invalid, because of this visit is not a proxy object, if you want to use a proxy object access, to dynamically access object to invoke from the beanFactory,
new objects, method, how to quote a null pointer, this and the new object
  • Related