1. 程式人生 > >web學習第一天

web學習第一天

system exceptio frame desc 運行 step 操作 pro 抽象方法

斷點:

快捷鍵:

f5:step into
f6:step over
f7:step return
drop to frame;跳到當前方法的第一行
resume:跳到下一個斷點



斷點應註意到問題
1,斷點調試完成後,要在breakpoints視圖中清除所有斷點
2,斷點調試完成後,一定記得結束運行斷點的jvm




可變參數
public static <T> List<T>asList(T... a)




枚舉
枚舉中的抽象方法需要實現
enum Grade{ //相當於class
A(" "),B(" "),C(" "),D(" "); //相當於Object
private String value;
private Grade(String value){
this.value =value;
}


**內省**:
Person類:
public class Person2 {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

}

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

import org.junit.Test;
//使用內省api操作bean屬性
public class introspector {
//得到Person中所有屬性
@Test
public void test() throws Exception {
BeanInfo info = Introspector.getBeanInfo(Person2.class);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
System.out.println(pd.getName());
}
}
//操作bean的指定屬性:age
@Test
public void test1() throws Exception{
Person2 p=new Person2();
PropertyDescriptor pd=new PropertyDescriptor("age",Person2.class);
//得到屬性的寫方法,為屬性值
Method method=pd.getWriteMethod();//public void setName(String name)
method.invoke(p, 45);
//System.out.println(p.getAge());
//獲取屬性的值
method=pd.getReadMethod();// public int getAge()
System.out.println(method.invoke(p, null));
}
@Test
//獲取當前操作的屬性類型
public void test3() throws Exception{
Person2 p=new Person2();
PropertyDescriptor pd=new PropertyDescriptor("age",Person2.class);
System.out.println(pd.getPropertyType());
}

}

web學習第一天