Java Reflection calls

Source: Internet
Author: 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 "excellent";
}
},
B ("89-70") {
Public String Lgetvalue () {
return "good";
}
},
C ("69-60") {
Public String Lgetvalue () {
return "Pass";
}
},
D ("59-0") {
Public String Lgetvalue () {
Return "Failed";
}
};
private String value;
Private Grad (String value) {
This.value=value;
}
Public String GetValue () {
return this.value;
}

Public abstract String Lgetvalue ();
}

Java Reflection calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.