首页 > 编程知识 正文

java多线程,JAVA泛型class

时间:2023-05-06 06:51:22 阅读:11252 作者:2173

1 .通用方法的定义和语法1.1定义通用方法是在调用方法时指定通用的具体类型。

【通用方法可以使方法独立于类的处理中指定的类型。 】

1.2语法修饰符t、e、…返回类型方法名称(形参数列表) )。

}

介于修饰符和返回类型之间的通用标识符t、e、是通用方法的标志,只有以此格式声明的方法才是通用方法。 声明通用方法时的通用标识符t、e、…表示可以使用在方法中声明的通用类型。 与通用类一样,通用标识符可以是任何类型,常见的有t、e、k、v等。 通用方法可以声明为静态,与常规静态方法相同。 2 .使用通用方法2.1通用方法声明

/* * author : north castle * createtime 33602021/10/23 *通用方法定义*/public class GenericMethod { //1.通用方法public tstring System.out.println ('一般统称方法: ' res ); 返回RES; }调用

/* * author : north castle * createtime :2021/10/23 */publicclassgenericmethodapplication { publicstaticvoidmain } stringcommonres 01=generic method.common method (' 001 ',' bb ' ); system.out.println(commonRES01; stringcommonres 02=generic method.common method (' 002 ',100 ); system.out.println(commonRES02; stringcommonres 03=generic method.common method (' 003 ',true ); system.out.println(commonRES03; system.out.println ((=================) () ) ); }运行结果

一般通用方法: 001-bb001-bb一般通用方法: 002-100002-100一般通用方法: 003-true 003-true============2.2静态通用

/* * author : north castle * createtime 33602021/10/23 *定义通用方法* /公共类通用方法{//2.静态通用方法System.out.println (静态通用方法: ' res ); 返回RES; }调用

package com.north castle.generic method;/* * author : north castle * createtime :2021/10/23 */publicclassgenericmethodapplication { publicstaticvoidmain } system.out.println(staticRES01; stringstaticres 02=generic method.static method (' 002 ',100,' c ' ); system.out.println(staticRES02; stringstaticres 03=generic method.static method (' 003 ',12.05d,false ); system.out.println(staticRES03; system.out.println ((=================) () ) ); }运行结果

静态通用方法: 001-aa-bb001-aa-bb静态通用方法: 002-100-c002-100-c静态通用方法: 003-12.05-false 003-12.05-false====

/* * * author : north castle * createtime 33602021/10/23 *定义通用方法* /公共类通用方法{//3.具有可变参数的通用方法PPP }调用

package com.north castle.generic method;/* * author : north castle * createtime :2021/10/23 */publicclassgenericmethodapplication { publicstaticvoidmain } system.out.println ((=================) () ) ); }运行结果

12300400500600========================3.完成congratula tions!

You are one step closer to success!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。