简体   繁体   English

package 内部的公共 class 看不到公共接口?

[英]Public class inside package can't see public interface?

I have a class:我有一个 class:

package Member;
public class Player implements Character{
...
}

and I have interface that is not inside the package:我有不在 package 内的接口:

public interface Character{
...
}

I think that public intefaces and classes are visible to each other no matter if they are in the same package, so why I can't implement Character in the Player class?我认为公共接口和类是彼此可见的,无论它们是否在同一个 package 中,那么为什么我不能在播放器 class 中实现字符? I have error: Cannot resolve symbol 'Character'我有错误:无法解析符号“字符”

If the interface (or any other class/enum you use) are in a different package, you need to either fully qualify it:如果接口(或您使用的任何其他类/枚举)位于不同的 package 中,则需要对其进行完全限定:

public class Player implements org.somepackage.Character {

or import it:或导入它:

import org.somepackage.Character;
public class Player implements Character {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在同一个包中实例化公共类 - Can't instantiate public class in the same package 无法访问公共类内的公共静态类的公共成员(均在单独的jar中) - Can't access public member of public static class inside public class (all in a separate jar) 从不同的包中调用公共课程中的公共课程 - Calling a public class inside a public class, from a different package 公共修饰符在包私有类中是多余的吗? - Is the public modifier redundant inside a package private class? 在另一个包中委托接口的方法时,如何使委托类非公开? - How can I make delegate class non-public when delegating methods of an interface in another package? 我的主要方法无法在Java的不同包中看到所有公共方法 - My main method can't see all public methods in a different package in java Java公共接口和公共类在同一个文件中 - Java public interface and public class in same file 可以从不同的包中访问在友好类中构建的公共构造函数吗? - Can a public constructor built inside a friendly class be accessed from a different package? 为什么我们不能在不修改“ public”的情况下实现从接口到抽象类的方法? - why we can't implement methods from interface to abstract class, without modifying “public”? 无法访问班级的公共领域 - Can't access a class's public field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM