Skip to content

Commit 974f418

Browse files
committed
获取Class方法案例
1 parent 5565e98 commit 974f418

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.javacore.rtti;
2+
3+
import java.lang.reflect.Constructor;
4+
import java.lang.reflect.Method;
5+
6+
/*
7+
* Copyright [2015] [Jeff Lee]
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
* * Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
/**
22+
* @author Jeff Lee
23+
* @since 2015-11-2 16:43:41
24+
* 获取Class方法案例
25+
*/
26+
public class ShowMethods {
27+
public static void main(String[] args) {
28+
try {
29+
Class<?> c = Class.forName("org.javacore.rtti.ShowMethods");
30+
Method[] methods = c.getMethods();
31+
Constructor[] constructors = c.getConstructors();
32+
for (Method m : methods)
33+
System.out.println(m.toGenericString());
34+
for (Constructor constructor : constructors)
35+
System.out.println(constructor.toGenericString());
36+
} catch (ClassNotFoundException e) {
37+
e.printStackTrace();
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)