Java泛型的简单实例
时间:2023-11-27 01:03:38
package com.chase.test;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
public class testT {
public static <T> void main(String[] args) {
testT classT = new testT();
List<T> find = classT.find(0, 10);
if (find != null && find.size()>0) {
for (T integer : find) {
System.out.println(integer);
}
}
// showList();
}
public static <T> void showList() {
testT classT = new testT();
List<T> find = classT.find(0, 10);
for (T t : find) {
System.out.println(t);
}
}
public <T> List<T> find(int begin, int end) {
List<T> list = new ArrayList<T>();
list.add((T)new Integer(222));
list.add((T)"111");
list.add((T)"昨天是重阳节!");
return list;
}
}
class TestGen0<K,V>{
public Hashtable<K,V> h=new Hashtable<K,V>();
public void put(K k, V v) {
h.put(k,v);
}
public V get(K k) {
return h.get(k);
}
public static void main(String args[]){
TestGen0<String,String> t=new TestGen0<String,String>();
t.put("key", "value");
String s=t.get("key");
System.out.println(s);
}
}
testT 输出:
222
111
昨天是重阳节!
TestGen0输出:
value
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringSecurity认证流程详解
![](https://img.aspxhome.com/file/2023/8/81988_0s.jpg)
java并发编程专题(三)----详解线程的同步
![](https://img.aspxhome.com/file/2023/1/108361_0s.png)
SpringBoot整合Elasticsearch并实现CRUD操作
![](https://img.aspxhome.com/file/2023/2/69282_0s.png)
浅谈Java中ThreadLocal内存泄露的原因及处理方式
![](https://img.aspxhome.com/file/2023/1/108211_0s.png)
springcloud 如何解决微服务之间token传递问题
android编程实现设置、打开wifi热点共享供他人连接的方法
Android中Java根据文件头获取文件类型的方法
使用itextpdf操作pdf的实例讲解
mybatis中<choose>标签的用法说明
![](https://img.aspxhome.com/file/2023/5/132185_0s.png)
C#中分部类和分部方法的应用
c#生成验证码程序
Java中BeanUtils.copyProperties基本用法与小坑
![](https://img.aspxhome.com/file/2023/3/73053_0s.png)
unity里获取text中文字宽度并截断省略的操作
![](https://img.aspxhome.com/file/2023/0/88410_0s.jpg)
Spring Boot 集成Redisson实现分布式锁详细案例
![](https://img.aspxhome.com/file/2023/5/83485_0s.png)
WinForm 自动完成控件实例代码简析
![](https://img.aspxhome.com/file/2023/7/108617_0s.png)
基于DateTime.ParseExact方法的使用详解
基于私钥加密公钥解密的RSA算法C#实现方法
Netty分布式高性能工具类FastThreadLocal和Recycler分析
![](https://img.aspxhome.com/file/2023/7/97957_0s.png)
C#中异步回调函数用法实例
java定义受限制的类型参数操作
![](https://img.aspxhome.com/file/2023/5/89605_0s.jpg)