+ 3

In python, if we can see other members using dir().. function.. How can I do it in Java?

27th Mar 2021, 6:21 AM
Name
Name - avatar
16 Answers
+ 6
When researching a topic in Java, my favorite resource is Baeldung. Definitely better quality than what you can find on geeksforgeeks. https://www.baeldung.com/java-reflection
27th Mar 2021, 8:03 AM
Tibor Santa
Tibor Santa - avatar
+ 2
Definition from Python docs: dir([object])¶ Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object. The first case (no arguments) has no equivalent in Java, because we cannot have free-hanging functions or variables defined without an actual parent class. The second case can be satisfied by java.lang.Class.getFields and other similar methods (even without using reflection). The sample code of Soumik is a very good example.
27th Mar 2021, 11:32 AM
Tibor Santa
Tibor Santa - avatar
27th Mar 2021, 10:45 AM
Soumik
Soumik - avatar
+ 1
I also wrote one, more compact https://code.sololearn.com/c68a257a21A1
27th Mar 2021, 10:55 AM
zemiak
+ 1
similar to dir() and __dir()__ concept is .toString() in java, it's the method of an object which you can rewrite to print info about an object in a format as you wish
27th Mar 2021, 11:01 AM
zemiak
0
Mireille, Can you please send me some links.. where I can learn about packages.. I mean which package is used for what.. and about there classes, methods?
27th Mar 2021, 7:28 AM
Name
Name - avatar
0
Ok, Kitten, I will visit chrome..
27th Mar 2021, 7:29 AM
Name
Name - avatar
0
Ok, Thanks, Kitten
27th Mar 2021, 7:33 AM
Name
Name - avatar
27th Mar 2021, 7:41 AM
Name
Name - avatar