读书人

视个泛型的例子

发布时间: 2014-01-15 15:40:23 作者: rapoo

看个泛型的例子

package com.wjy.effective;public class FStyle {    public <E> E getField(E param){        E result=param;        return result;    }}

?

客户端程序:

package com.wjy.effective;public class TestFStyle {    public static void main(String args[]){        FStyle fStyle=new FStyle();//        int n=fStyle.getField(1)+2;        String s=fStyle.getField("hello")+2;        //        System.out.println("result is; "+n);        System.out.println("result is; "+s);    }}

?

运行结果:

//result is; 3result is; hello2

?

读书人网 >软件架构设计

热点推荐