Java?????? Map?????
???????????? ???????[ 2013/12/19 11:32:05 ] ????????
???????????????
?????????????
????????????????????????????????
??????????????????????????????????????????????????????????
class Demo<T>{
//show()??????????????????????
public void show(T t){
System.out.println("show:"+t);
}
//print()???????????????????
public <Q> void print(Q q){
System.out.println("print:"+q);
}
//???????????
public static <W> void method(W w){
System.out.println("methld:"+w);
}
}
class GenericDemo{
public static void main(String[] args){
Demo<String> d = new Demo<String>();
d.print(8);
d.print(new Integer(5));
d.print("heihei");
d.show("haha");
//d.show(5);
d.method("Hello");
}
}
/*
???
print:8
print:5
print:heihei
show:haha
methld:Hello
*/
???????????
?????????<? extends E> ???????E???????E?????????
?????????<? super E> ???????E???????E????????
import java.util.*;
class Person{
private String name;
Person(String name){
this.name=name;
}
public String getName(){
return name;
}
}
class Student extends Person{
Student(String name){
super(name);
}
}
class GenericDemo{
public static void main(String[] args){
ArrayList<Person> arr1 = new ArrayList<Person>();
arr1.add(new Person("Person01"));
arr1.add(new Person("Person02"));
arr1.add(new Person("Person03"));
ArrayList<Student> arr2 = new ArrayList<Student>();
arr2.add(new Student("Student01"));
arr2.add(new Student("Student02"));
arr2.add(new Student("Student03"));
printColl(arr2);
}
public static void printColl(ArrayList<? extends Person> arr1){
//?????????Person????Person??????????Person??
Iterator<? extends Person> it = arr1.iterator();
while(it.hasNext()){
System.out.println(it.next().getName());
}
}
}
/*
???
Student01
Student02
Student03
*/
|
???????????
???????????????????????????
import java.util.*;
class GenericDemo{
public static void main(String[] args){
//????Student?????????????????
TreeSet<Student> ts = new TreeSet<Student>(new Comp());
ts.add(new Student("Student01"));
ts.add(new Student("Student05"));
ts.add(new Student("Student09"));
ts.add(new Student("Student08"));
Iterator<Student> it = ts.iterator();
while(it.hasNext()){
System.out.println(it.next().getName());
}
//????Worker?????????????????
TreeSet<Worker> wo = new TreeSet<Worker>(new Comp());
wo.add(new Worker("Worker01"));
wo.add(new Worker("Worker05"));
wo.add(new Worker("Worker09"));
wo.add(new Worker("Worker08"));
wo.add(new Worker("Worker07"));
Iterator<Worker> it1 = wo.iterator();
while(it1.hasNext()){
System.out.println(it1.next().getName());
}
}
}
/*
//????????
class StudentComp implements Comparator<Student>{
public int compare(Student s1??Student s2){
return s1.getName().compareTo(s2.getName());
}
}
//????????
class WorkerComp implements Comparator<Worker>{
public int compare(Worker s1??Worker s2){
return s1.getName().compareTo(s2.getName());
}
}
//?????????????????????????£???????????Person
*/
class Comp implements Comparator<Person>{
public int compare(Person s1??Person s2){
//return s1.getName().compareTo(s2.getName());//??????
return s2.getName().compareTo(s1.getName());//??????
}
}
class Person{
private String name;
Person(String name){
this.name = name;
}
public String getName(){
return name;
}
public String toString(){
return "person:"+name;
}
}
class Student extends Person{
Student(String name){
super(name);
}
}
class Worker extends Person{
Worker(String name){
super(name);
}
}
/*
???
Student09
Student08
Student05
Student01
Worker09
Worker08
Worker07
Worker05
Worker01
*/
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????