import com.sun.org.apache.xerces.internal.impl.dv.dtd.NMTOKENDatatypeValidator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* Created by kaizige on 2017/7/3.
*/
public class Stack2<E> {
private Object[] eles;
private int size=0;
private static final int CAPATY=10;
@SuppressWarnings("unchecdked")
public Stack2(){
eles=new Object[CAPATY];
}
public void push(E o){
eles[size++]=o;
}
public E pop(){
if(size==0){
throw new RuntimeException("没有元素");
}
E o=(E) eles[--size];
eles[size]=null;
return o;
}
public void pushAll(Iterator<? extends E> src){
while(src.hasNext()){
push(src.next());
}
}
public void popAll(Collection<? super E > des){
des.add(pop());
}
}
显示的类型参数:
public class FunctionFactory {
public static <E> Set<E> union(Set<? extends E> s1, Set<? extends E> s2){
Set<E> r=new HashSet<E>(s1);
r.addAll(s2);
return r;
}
public static void main(String[] args) {
Set<Integer> s1=new HashSet<Integer>();
s1.add(2);
Set<Double> s2=new HashSet<Double>();
s2.add(2.3);
Set<Number> s=union(s1,s2);
}