define an entityObject:
java 代码
- class Employee {
-
- public Employee() {
- age = 10;
- name = null;
- }
-
- public void setAge(int a) {
- age = a;
- }
-
- public int getAge() {
- return age;
- }
-
- public void printInfo(String name,int age){
- System.out.println("myName is:"+name+" myAge is:"+age);
- }
- private int age;
- private String name;
- }
Test Codes:
java 代码
- class ReflectTest{
- public static void main(String[] args){
- Employee emp=new Employee();
- Class c=emp.getClass();
- try{
- Method printInfo=c.getMethod("printInfo", new Class[]{String.class,int.class});
- Object[] args1=new Object[]{"zhuhaihua",23};
- printInfo.invoke(emp, args1);
- }catch(Exception e){
- }
- }
- }
just copy two pieces of code into the IDE(just like Eclipse) then run the ReflectTest class,you will get the result:
myName is:zhuhaihua myAge is:23
分享到:
相关推荐
The authors present exceptionally clear and practical explanations drawn from their immense experience pioneering the Java platform, and illustrate many of these examples using simple mathematical ...
A Short History of Java 9 Common Misconceptions about Java 11 Chapter 2: The Java Programming Environment 15 Installing the Java Development Kit 16 Choosing a Development Environment 21 Using ...
This revised edition of the classic Core Java™, Volume I–Fundamentals, is the definitive guide to Java for serious programmers who want to put Java to work on real projects. Fully updated for the ...
I've conducted over 100 interviews at Fortune 500 companies and meticulously collected the most effective questions with simple, straightforward explanations. This book will teach you object-...
JAVA相关基础知识 1、面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面。抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用...
The first chapter is a tutorial on the basic concepts of Go, introduced through programs for file I/O and text processing, simple graphics, and web clients and servers. Early chapters cover the ...
超级有影响力的Java面试题大全文档 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面。抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节。...
Write simple multicore programs using Clojure's core concepts, such as atoms, agents, and refs Get to grips with Clojure's concurrency and state-management primitives in depth Analyze latency using ...
Java SE5 and SE6 .................. 2 Java SE6 ......................................... 2 The 4th edition........................ 2 Changes .......................................... 3 Note on the ...
Javalin - A simple web framework for Java and Kotlin Javalin is a very lightweight web framework for Kotlin and Java which supports WebSockets, HTTP2 and async requests. Javalin’s main goals are ...
The Relationship of C# to .NET 4 The Common Language Runtime 4 Advantages of Managed Code 4 A Closer Look at Intermediate Language 7 Support for Object Orientation and Interfaces 8 Distinct Value and ...
《Thingking in Java》(第一版中文)是这样描述设计模式的:他在由 Gamma, Helm 和 Johnson Vlissides 简称 Gang of Four(四人 帮),缩写 GoF 编著的《Design Patterns》一书中被定义成一个“里程碑”。事实上,那本书...
9.4.6. Working with Fractions of Seconds 9.4.7. Sunrise / Sunset 9.5. Creation of dates 9.5.1. Create the actual date 9.5.2. Create a date from database 9.5.3. Create dates from an array 9.6. ...