I searched on the Internet, but I did not find any articles to find out what kind of Class it is and what it is eaten with. What kind of person is this?
- 2In Shieldt, in the Complete Manual, this question is well disclosed. - post_zeew
- fourPossible duplicate question: What is .class? - andreycha
- oneImagine that you need to do something like a command line interpreter that loads and launches the programs specified by the user. Then you need a type to represent loadable and executable programs. The programs executed by the JVM are represented on the disk by class files, and in memory are represented by objects of type Class. - rfq
2 answers
In Java, almost all entities are objects, with the exception of primitive types. Every object has a class. Classes themselves are also objects, and they belong to the Class class.
Class has no public constructors. Class is a generic type. Class methods are designed to obtain information about a class (an object of type Class). For example, you can find out the full name of the class, what annotations it has, what constructors, etc. These methods are needed for reflection. With the help of reflection, you can create objects that belong to this class, and you may not know the object class in advance.
There are libraries that allow you to create Class objects on the fly, i.e. You can create a new class while the program is running and you can also change an existing class.
- What class has constructors and methods? Why is it needed? - bsuart
- @ bsuart2017 updated answer - Mikhail Vaysman
- one@rfq, you have a strange approach. I need it in order to understand it thoroughly for myself, since I’m meeting with these things for the first time. - bsuart
- oneRead about reflection, everything will become clear - Flippy
Class is the class included in the java.lang . It is eaten only when it is necessary to use reflection.
So you can do
Class clazz = SecondActivity.class; Places the activity class in the clazz variable clazz
- it is impossible to do so - "class" cannot be used as an identifier :) - rfq
- "
Classis the class included in thejava.lang.reflect" - and you do not confuse anything? - post_zeew - Already noticed, hurried - Flippy
- The variable name was changed because
classis a keyword? - Flippy - one@ SergeyGrushin is absolutely right, and without this edit, the code was syntactically incorrect ¯ \ _ (ツ) _ / ¯ - D-side