看个泛型的例子

来源:互联网 发布:酒店网络所需设备清单 编辑:程序博客网 时间:2024/06/05 00:32
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 is3result is; hello2

 

0 0
原创粉丝点击