【发布时间】:2018-04-20 08:08:09
【问题描述】:
我已经定义了一个简单的通用接口:
public interface I1 <A> {
public void display1(A x);
}
还有一个简单的泛型类:
public class c11<A> implements I1<A> {
@Override
public void display1(A x) {
System.out.println(x + " is of type " + x.getClass());
}
}
当我尝试如下实例化时,出现错误:
int x = 5;
c11<Integer> s1 = new c11<Integer>(x);
s1.display1(x);
非常感谢您的帮助。
【问题讨论】:
-
什么错误?在哪一行?
-
你的构造函数是在哪里定义的?
-
Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. 见:How to create a Minimal, Complete, and Verifiable example。
-
对代码的注释:Java 中的类(如接口和枚举)总是以大写字母开头。
-
把
new c11<Integer>(x);改成new c11<Integer>();能用吗?
标签: java class generics interface