restTemplate cannot be resolved to a variableJava in mainCalculateReturnsAfterRefactor

When calling getPortfolioManager(RestTemplate restTemplate) to get a new instance of PortfolioManager,
I am getting an error “restTemplate cannot be resolved to a variable”. If I create a local variable(restTemplate) to pass as an argument, how should I initialize it?

Have you declared RestTemplate as a global Variable?

No. I’am not able to understand how should i pass RestTemplate to getPortfolioManager() since there is no local variable name restTemplate in mainCalculateReturnsAfterRefactor().
And if i have to create a local variable in the function mainCalculateReturnsAfterRefactor() how to intialize it?

Refer to this FAQ

I went through this FAQ earlier. I have implemented the factory class, but not able to get a new instance of portfolioManager because of the error mentioned above.

Hey since you only want a new instance of PortfolioManager,refer to this.

But the Implementation class(PortfolioManagerImpl) of interface(PortfolioManager) has a member variable restTemplate, while creating an instance from mainCalculateReturnsAfterRefactor() i have to pass restTemplate (new PortfolioManagerImpl(restTemplate) or using factory class PortfolioManagerFactory.getPortfolioManager(restTemplate)) .

My question is how do i pass this variable(restTemplate).
Thanks in advance.

Make a deprecated constructor or function. I think you’re not making one.

This is the issue i’m facing.

@ankush Create an object of RestTemplate and use it in the mainCalculateReturnsAfterRefactor in order to call the getPortfolioManager(RestTemplate restTemplate).

Also refer to this FAQ

I guess, the thread which you have shared also provides a solution, if you read properly.

Hey,

You need to create your rest template variable by using - RestTemplate resttemplate

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.