ITeye博客

Java泛型接口

cjx186 · 2012-09-16 17:40 · java · 编程语言 · Markdown

package me.cjx.example;
interface Demo<T> {
    public void print(T param);
}
// 实现泛型接口一
class Imple1<T> implements Demo<T> {
    public void print(T param) {
        System.out.println("param = " + param);
    }
}
// 实现泛型接口二
class Imple2 implements Demo<Imple2> {
    public void print(Imple2 param) {
        System.out.println("param = " + param);
    }
}
public class GenericsDemo {
    public static void main(String[] args) {
        Imple1<String> demo = new Imple1<String>();
        demo.print("Hello, Wrold!");
        Imple2 im = new Imple2();
        im.print(new Imple2());
    }
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。