+ 3
In python, if we can see other members using dir().. function.. How can I do it in Java?
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
+ 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.
+ 1
I also wrote one, more compact
https://code.sololearn.com/c68a257a21A1
+ 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
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?
0
Ok, Kitten, I will visit chrome..
0
Ok, Thanks, Kitten
0
Kitten, did you talk about this at first?
https://www.google.com/amp/s/www.geeksforgeeks.org/reflection-in-java/amp/