I got a simple question:
Why does Eclipse scream about implementing these tw开发者_如何学运维o interfaces?
public abstract class Gateway implements IPlayerity, IItemity {
public interface IPlayerity { ... }
public interface IItemity { ... }
// I...ity
}
I get this error message:
IPlayerity cannot be resolved to a type
You have a cyclic dependency that can't be resolved given the way the JLS works (although I'm not sure where in the JLS this is documented).
The interfaces IPlayerity and IItemity are not visible to the NestedInterfaces class header definition, since they are inside it. I can fix this by changing your program to
public class NestedInterfaces implements
NestedInterfaces.IPlayerity, NestedInterfaces.IItemity
{
public interface IPlayerity {}
public interface IItemity {}
}
but then Eclipse gives me this error, which is much more clear:
Multiple markers at this line
- Cycle detected: the type NestedInterfaces cannot extend/implement itself or one of its own member types
- Cycle detected: the type NestedInterfaces cannot extend/implement itself or one of its own member types
Declare the interfaces in another file. Its apparent to me that a top-level class cannot implement the interfaces nested within itself ( although I'm not sure why ).
If you want to keep the interfaces within the same file, then you have to change the modifier from public to default and declare them after the class definition.
I see that these two interface is not default java interface, right? So, if you get the error "IPlayerity cannot be resolved to a type.", check whether you import the right packages yet. I should comment for this, but I just cant. Have fun.
If it cannot be resolved as a type, then it cannot be "seen". You should add an import for the interface:
import package.Gateway.IPlayerity
import package.Gateway.IItemity
still, I have a feeling that then the compiler will throw some other weird cyclic errors..
It's better if you define the interfaces in another file.
精彩评论