java 反射調用

來源:互聯網
上載者:User

標籤:

public void d1() throws ReflectiveOperationException{
Class cl=Class.forName("com.daben.dt.class1");
class1 c1=(class1) cl.newInstance();
Method mth= cl.getMethod("saylist", null);
mth.invoke(c1,null);
//class1 c1=(class1) cl.newInstance();
//Constructor c= cl.getConstructor(null);

//class1 c1=(class1) c.newInstance();
//c1.saylist();
}

 

 

public class class1 {
public class1(){
System.out.println("null");
}
public class1(String aa){
System.out.println("string");
}
private class1(List aa){
System.out.println("list");
}
public void say(){
System.out.println("hello");
}

public void saylist(){
int[] aa={1,2,3,4,5,6,7,8,9,10};
for(int num:aa){
//aa[num]=10;
System.out.println(num);
}
}
public void dto(){
List list=new ArrayList();
list.add(1);
list.add(2);
list.add(3);
Iterator it=list.iterator();
while(it.hasNext()){
int j=(Integer)it.next();
System.out.println(j);
}
}
public void print(Grad A){
String value=A.lgetvalue();
System.out.println(value);
}
@Test
public void test(){
print(Grad.B);
}
}

enum Grad{
A("100-90"){
public String lgetvalue(){
return "優秀";
}
},
B("89-70"){
public String lgetvalue(){
return "良好";
}
},
C("69-60"){
public String lgetvalue(){
return "及格";
}
},
D("59-0"){
public String lgetvalue(){
return "不及格";
}
};
private String value;
private Grad(String value){
this.value=value;
}
public String getvalue(){
return this.value;
}

public abstract String lgetvalue();
}

java 反射調用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.