惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
InfoQ
H
Help Net Security
大猫的无限游戏
大猫的无限游戏
L
LangChain Blog
F
Full Disclosure
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
博客园 - Franky
IT之家
IT之家
K
Kaspersky official blog
Simon Willison's Weblog
Simon Willison's Weblog
C
Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
V
Vulnerabilities – Threatpost
Vercel News
Vercel News
博客园 - 司徒正美
G
Google Developers Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Blog — PlanetScale
Blog — PlanetScale
Help Net Security
Help Net Security
S
Secure Thoughts
有赞技术团队
有赞技术团队
P
Privacy International News Feed
S
Schneier on Security
T
Troy Hunt's Blog
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
H
Heimdal Security Blog
Latest news
Latest news
S
Security @ Cisco Blogs
博客园 - 聂微东
The Hacker News
The Hacker News
B
Blog
Forbes - Security
Forbes - Security
A
About on SuperTechFans
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
罗磊的独立博客
雷峰网
雷峰网

博客园 - Ring

运行Java cmd程序 找不到或无法加载主类怎么解决 Generics and Collection (1) mybatis, spring, springmvc 什么时候该用NoSQL? 如何学习Javascript 好文章尽收眼底 事务和锁 索引 VS调试Javascript. Asp.net常用状态管理方案分析 .NET中的缓存知识总结 "The server has rejected the client credentials"解决方案 - Ring 有关IIS7概述以及配置和开发的几篇文章摘录 CodeForFun--编写自动登录Email的程序 是什么使得我的进程崩溃了? OutOfMemory这家伙是谁?为什么我还留有许多内存,它却使进程崩溃了? ASP.NET 崩溃-SiteMap中疯狂的循环 何时.NET中AppDomain会回收? .NET如何使用内存---餐馆案例分析
Generics and Collection (2)
Ring · 2015-05-02 · via 博客园 - Ring

Integer is a subtype of Number
Double is a subtype of Number
ArrayList<E> is a subtype of List<E>
List<E> is a subtype of Collection<E>
Collection<E> is a subtype of Iterable<E>

public class ArrayList<E> extends AbstractList<E>
        implements List<E>, RandomAccess, Cloneable, java.io.Serializable
    public static void main(String args[]) {
        List<Number> nums = new ArrayList<Number>();
        List<Integer> ints = Arrays.asList(1, 2);
        List<Double> dbls = Arrays.asList(2.78, 3.14);
        nums.addAll(ints);
        nums.addAll(dbls); 
        for(Number d: nums)
            System.out.println(d);
    }
package cn.galc.test;

import java.util.*;
 
class Collections{
    public static <T> List<T> toList(T[] arr)
    {
        List<T> list = new ArrayList<T>();
        for (T t: arr)
        {
            list.add(t);
        }
        return list;
    }
    
    public static <T> void copy(List<? super T> dst, List<? extends T> src) {
        for (int i = 0; i < src.size(); i++) {
        dst.set(i, src.get(i));
        }
    }
}
 
public class Test {     
    public static void main(String args[]) {
        List<Object> objs = Arrays.<Object>asList(2, 3.14, "four");
        List<Integer> ints = Arrays.asList(5, 6);
        Collections.copy(objs, ints);
        for(Object o: objs)
            System.out.println(o);
    }
}