FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaExercises/Java 3/HW71Lesson.java at master · biblelamp/JavaExercises · GitHub
biblelamp
/
JavaExercises
Public
Notifications
You must be signed in to change notification settings
Fork
130
Star
153
Code
Issues
1
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaExercises
/
Java 3
/
HW71Lesson.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (50 loc) · 1.9 KB
Breadcrumbs
JavaExercises
/
Java 3
/
HW71Lesson.java
Copy path
File metadata and controls
57 lines (50 loc) · 1.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Java. Level 3. Lesson 7. Homework
* 1. Create a method-researcher. At the input of the class name,
* the method outputs to the console all the information about the class
* that can be obtained using Reflection
*
* @author Sergey Iryupin
* @version Mar 09, 2018
* @link https://github.com/biblelamp
*/
import
java
.
lang
.
reflect
.
Field
;
import
java
.
lang
.
reflect
.
Constructor
;
import
java
.
lang
.
reflect
.
Method
;
public
class
HW71Lesson
{
public
static
void
main
(
String
[]
args
) {
HW71Lesson
hw
=
new
HW71Lesson
();
hw
.
getClassInformation
(
(
args
.
length
==
0
)?
"java.lang.String"
:
args
[
0
]);
}
void
getClassInformation
(
String
className
) {
Class
classObj
;
try
{
classObj
=
Class
.
forName
(
className
);
}
catch
(
ClassNotFoundException
ex
) {
ex
.
printStackTrace
();
return
;
}
// get full and short names
System
.
out
.
println
(
"Full name: "
+
classObj
.
getName
());
System
.
out
.
println
(
"Short name: "
+
classObj
.
getSimpleName
());
// get full and short names of superclass
System
.
out
.
println
(
"Parent full name: "
+
classObj
.
getSuperclass
().
getName
());
System
.
out
.
println
(
"Parent short name: "
+
classObj
.
getSuperclass
().
getSimpleName
());
// get public fields of class
System
.
out
.
println
(
"
\n
Public fields:"
);
for
(
Field
field
:
classObj
.
getFields
())
System
.
out
.
println
(
field
.
getType
().
getName
() +
" "
+
field
.
getName
());
// get public constructors
System
.
out
.
println
(
"
\n
Public constructors:"
);
for
(
Constructor
constructor
:
classObj
.
getConstructors
())
System
.
out
.
println
(
constructor
);
// get public methods
System
.
out
.
println
(
"
\n
Public methods:"
);
for
(
Method
method
:
classObj
.
getMethods
())
System
.
out
.
println
(
method
);
}
}
Back
|
FazBrowse Home
|
New Git URL