T
T
thatmaniscool2019-01-12 19:43:25
Java
thatmaniscool, 2019-01-12 19:43:25

Why use a similar notation in java?

Sometimes in the code you can find a similar entry
foo (NameClass.class);
What is it for and how to use it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey〒., 2019-01-12
@axifive

With the help , a Class.class object is obtained , so that in the future, through reflection, it would be possible to perish properties at runtime.

Y
YershovAleksandr, 2019-01-12
@YershovAleksandr

https://www.youtube.com/watch?v=FfLRFWKUYLU&list=P...
Watch from the 32nd minute.

A
Alexander Kotovsky, 2019-01-12
@kotovsky_art

This is an example of using the Reflection API. One of the ways to achieve greater flexibility in the behavior of the program at runtime. In this case, you are passing the class itself. The method signature looks like void foo(Class c) {}. In this case, you do not need to create an instance of the class. The method itself will determine the method and necessity of creating an instance of this class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question