Java. Lang. illegalstateexception: cannot convert value of Type

Source: Internet
Author: User

Java. Lang. illegalstateexception: cannot convert value of type ...... To ......

No matching editors or conversion strategy found

This problem is really confusing.

No matching editors or conversion strategy found.

After the problem was solved, I still don't know why. Let's talk about my problems and solutions.

First, I have three classes: accountservice, drawaccountservice, and curraccountservice. These three classes all inherit from a crudservice and have similar basic functions. However, they target different Dao classes, and different Dao classes target different entities and tables.

I called them in three related actions, corresponding to accountinteraction, drawaccountinteraction, and curraccountinteraction.

In accountinteraction, I autowared the accountservice. The definition is as follows:

private AccountService accountService;@Autowiredpublic void setAccountService(AccountService accountService) {this.accountService = accountService;}

Then call this accountservice to execute some related functions. Well, these are all correct. The problem is as follows.

Then, in drawaccountinteraction and curraccountinteraction, I also autowared their corresponding drawaccountservice and curraccountservice. The classes are different, but the variable names are the same, in these two actions, my reference statements are as follows:

private DrawAccountService accountService;@Autowiredpublic void setAccountService(DrawAccountService accountService) {this.accountService = accountService;}
private CurrAccountService accountService;@Autowiredpublic void setAccountService(CurrAccountService accountService) {this.accountService = accountService;}

Note: The Defined variable types are different, but the variable names are the same.

When calling the two service-related functions in drawaccountinteraction and curraccountinteraction, an error message is displayed, such as Java. Lang. illegalstateexception: cannot convert value of Type accountservice to drawaccountservcie. I am a bit puzzled, because I have not switched?

Later, the dead horse was a dead horse doctor. Since all the prompted errors mentioned accountservice, I changed this variable to another name. So in drawaccountinteraction and curraccountinteraction, I changed the two referenced variables to the following names:

private DrawAccountService drawAccountService;@Autowiredpublic void setDrawAccountService(DrawAccountService drawAccountService) {this.drawAccountService = drawAccountService;}
private CurrentAccountService currAccountService;@Autowiredpublic void setCurrAccountService(CurrentAccountService currAccountService) {this.currAccountService = currAccountService;}

Yes, the variable name is modified, and then everything is normal. To be honest, I cannot understand it.

For now.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.