javac complains: cannot find symbol on enum implementing interface

巧了我就是萌 提交于 2019-12-03 10:32:32

Could this be Bug 6522780?
Or Bug 6330385?
Or Bug 6724345 - fixed in JDK 7 - so you could test that.

It might be a bug in Sun's javac. func is an enum (even if that enum implements Operation) and the Enum class doesn't have a method call(). To solve the issue, I suggest to change the assignment:

Operation func = OperationDefinitions.CONCATENATE;

That will also make it clear what you expect: An operation, not an enum. The enum is just a convenient way to collect all possible operations (a container if you wish).

Miqueias Gomes

This is a bug, as "Stephen Denne" has showed us, but if you can't do the update to a new version (but should)... Just remove the inteface from OperationDefinitions and put the method ...call(...) at the enum, like this:

public abstract Object call(List params);

Should work.

I suspect this is actually a bug in javac; OperationDefinitions definitely does have an (abstract) method call(java.util.List), since it implements the Operation interface. And the class definition is valid, since all constants provide a concrete implementation of this interface.

One thing that might be partially responsible for this, is that to my knowledge all methods defined in an interface must be public. If you've really defined the call method in the interface with the default access modifier, I'd expect the compiler to reject it - but if it doesn't then it wouldn't surprise me to see problems down the line. If this was a typo then fine, but if it's like that in your code try declaring it as public and seeing if the problem goes away.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!