欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

泛型,

来源: javaer 分享于  点击 36388 次 点评:227

泛型,


1.泛型类
/*自定义泛型类
* 1.泛型类的属性类型(字段),跟泛型类是同一个类型。
* 2.泛型不能使用在静态属性上 //private static T javase;
*/

public class MyStudent<T> {

private T javase;
public T getJavase() {
    return javase;
}

public void setJavase(T javase) {
    this.javase = javase;
}

public MyStudent(){

}

public MyStudent(T javase) {
    super();
    this.javase = javase;
}

}
/*
* 1.泛型方法会自动检测类型
*
*/
public class Test {

public static void main(String[] args) {
    MyStudent<Integer> student=new MyStudent<Integer>();
    student.setJavase(80);
}

}

相关文章

    暂无相关文章

用户点评