I've been trying to understand that how the Class Class
actually works in java but everywhere I look all it says is that its references
represent the Classes
and Interfaces
in a running java application but nowhere I've managed to find that how actually it does that? Does it store the name of the Classes
as a String property? or is it something else? Also I've seen in Spring
applications we pass SpringApplication.run(SomeClass.class, args)
and all people say that we are passing it because because we need to pass the name of class, If it so then why can't we just pass it as a String like this SpringApplication.run("Name of that class", args)
? And what is the advantage of getting the object of Class Class
for a certain Class
or Interface
?
Asked
Active
Viewed 31 times
0

ansme
- 413
- 2
- 11
-
Did you try to look up the javadoc for Class? I use "google java class documentation" for this. – NomadMaker May 01 '21 at 13:54
-
For object-oriented programming, it does not matter "how" something is implemented, it only matters "what" it does. So from a pure use point of view there's no need to know what goes on inside a Class object. Of course, if your purpose is education, that's entirely different. – something May 01 '21 at 13:58
-
@NomadMaker I've already tried the official documentation but still can't find a use case. – ansme May 01 '21 at 14:00
-
1You can get the name of the class from a `Class` object. You can get its methods and call them (reflection), you can do a lot of things with it, which are described in plenty of documentation. – Kayaman May 01 '21 at 14:01
-
You asked "how" rather than a use-case. You should search for tutorials in that case. – NomadMaker May 01 '21 at 14:01
-
@something I just wanna know how the object can be used in an application, That's why I asked what are it's advantages. – ansme May 01 '21 at 14:02
-
@Kayaman Can you please provide a link for the documentation? – ansme May 01 '21 at 14:04
-
1See duplicates for more information, internet has the documentation somewhere. – Kayaman May 01 '21 at 14:06
-
@Kayaman Thank you! the duplicates made it much clearer! :D – ansme May 01 '21 at 17:59