简体   繁体   中英

Cutting down code: “The method changeVote in the type VoteService is not applicable for the arguments (void)”

I am kind of new to Java and am trying to cut down unneccessary lines of code. I am getting an error, and belive I was able to do this in c# or c++: I wish to bind the following 2 lines of code in one:

checkVote.setType(null);                
changeVote(checkVote);
//into
changeVote(checkVote.setType(null));

I get the error from the title. I know why it occurs (the setter return type is void, and there is no changeVote(void) method). But I still feel like there are ways of doing what I want.

You can change the method setType to return this instead of void . This would violate the JavaBean convention, but it could be suitable for your use case.

This approach is used in the builder pattern

method changeVote possibly takes only checkVote as parameter and you are trying to pass a paramter which is returnig void. In fact this is not even possible in C++.

So those 2 lines continue to be same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM