package com.www.java;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Code01 {
//class body
public static void main(String[] args) {
List<String> list = new ArrayList();
list.add("123");
list.add("aaa");
list.add("222");
//list.add(333);
// for (Object object : list) {
// System.out.println(object);
// }
Iterator it = list.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}
package com.www.java;
public class demo01<T> {
//class body
public T xx;
public T getXx() {
return xx;
}
public void setXx(T xx) {
this.xx = xx;
}
}
package com.www.java;
public class demo02 {
//class body
public <T> void aa(){};
}
package com.www.java;
import java.util.ArrayList;
import java.util.List;
public class demo03 {
//class body
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add(new String("abc"));
list.add(new String("def"));
// list.add(new Integer(100));
// list.add(new Double(1.2));
}
}
package com.www.java;
import java.util.ArrayList;
import java.util.List;
public class demo04 {
//class body
private void display(List<?> list){
System.out.println(list);
}
public static void main(String[] args) {
Integer integer = new Integer(100);
Number number = new Integer(200);
Object object = new Integer(300);
List<Integer> list1 = new ArrayList<Integer>();
list1.add(integer);
List<Number> list2 = new ArrayList<Number>();
list2.add(number);
List<Object> list3 = new ArrayList<Object>();
list3.add(object);
demo04 demo04 = new demo04();
demo04.display(list1);
demo04.display(list2);
demo04.display(list3);
}
}
package com.www.java;
import java.util.ArrayList;
import java.util.List;
public class demo05 {
//class body
private void display(List<? extends Number> list){
System.out.println(list);
}
public static void main(String[] args) {
Integer integer = new Integer(100);
Number number = new Integer(200);
Object object = new Integer(300);
List<Integer> list1 = new ArrayList<Integer>();
list1.add(integer);
List<Number> list2 = new ArrayList<Number>();
list2.add(number);
List<Object> list3 = new ArrayList<Object>();
list3.add(object);
demo05 demo05 = new demo05();
demo05.display(list1);
demo05.display(list2);
//demo05.display(list3);
}
}
package com.www.java;
import java.util.ArrayList;
import java.util.List;
public class demo06 {
//class body
private void display(List<? super Number> list){
System.out.println(list);
}
public static void main(String[] args) {
Integer integer = new Integer(100);
Number number = new Integer(200);
Object object = new Integer(300);
List<Integer> list1 = new ArrayList<Integer>();
list1.add(integer);
List<Number> list2 = new ArrayList<Number>();
list2.add(number);
List<Object> list3 = new ArrayList<Object>();
list3.add(object);
demo06 demo06 = new demo06();
//demo06.display(list1);
demo06.display(list2);
demo06.display(list3);
}
}
package com.www.java;
public class demo07 {
//class body
public <T extends Number> void method(T t){
System.out.println(t);
}
public static void main(String[] args) {
demo07 demo07 = new demo07();
demo07.method(new Integer(100));
demo07.method(new Double(100));
//demo07.method(new String("abc"));
}
}
package com.www.java;
public class demo08<T> {
//class body
T var;
public demo08(T var) {
super();
this.var = var;
}
public demo08() {
super();
}
public T getVar() {
return var;
}
public void setVar(T var) {
this.var = var;
}
}
package com.www.java;
public class test01 {
//class body
public static void main(String[] args) {
//1.泛型类
//demo01<String> demo01 = new demo01<String>();
//泛型接口
}
}
package com.www.java;
public class test02 {
//class body
public static void main(String[] args) {
demo08<String> demo08 = new demo08<String>(new String("value"));
System.out.println(demo08.getVar());
demo08<Integer> demo082 = new demo08<Integer>(new Integer(100));
System.out.println(demo082.getVar());
}
}
没死
就不要把自己当成废物
《每天一张正能量》