我想在此类中包含一个 Printable
接口(interface),但它显示错误。
error:Class file collision: A resource exists with a different case:
'/example01/bin/com/example/test/test.class'.
这是我的代码
package com.example.test;
import com.example.test.Printable;
class A implements Printable {
public void a() {
System.out.println("a method");
}
@Override
public void b() {
}
}
abstract class B implements Printable {
public void b() {
System.out.println("b method");
}
}
class Call {
void invoke(Printable p) {// upcasting
if (p instanceof A) {
A a = (A) p;// Downcasting
a.a();
}
if (p instanceof B) {
B b = (B) p;// Downcasting
b.b();
}
}
}// end of Call class
class Test {
public static void main(String args[]) {
Printable p = new A();
Call c = new Call();
c.invoke(p);
}
}
这是我的可打印接口(interface)类代码
public interface Printable {
public void a ();
public void b();
}
那么我如何将 Printable 接口(interface)导入到此类中,我们将不胜感激。谢谢
最佳答案
这是我将接口(interface)嵌入到类中的方法:
public class NestedClassInterface {
/**
* Nested interface
* @author Markus
*/
public interface Printable {
public void a();
}
/**
* MAIN
* @param args
*/
public static void main(String[] args) {
Printable t = new MyTest();
t.a();
}
/**
* Static class (otherwise the compiler cannot find it)
* @author Markus
*
*/
public static class MyTest
implements Printable {
public void a() {
System.out.println("NestedClassInterface.MyTest.a()");
}
}
}
注释
- 如Admit亮点: 一个文件中只允许存在一 (1) 个类。命名应保持一致。
java.util.Map
使用相同的方法来定义其条目Map.Entry
:http://www.docjar.com/html/api/java/util/Map.java.html
让我们了解您的进展。
关于java - 如何在java类中包含接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25203133/