Sergey Sergey - 1 year ago 105
Java Question

What is the difference between java.lang.class<Cls> and just Cls?

What is the difference between

and just

I need to pass this to a function:


I tried
new TermlistRequest()
but it is this:


Can you explain what is it in Java? And how to create an object of this type?

PS: I know it may be very simple, but I'm new to Java

Answer Source

The difference between Class<T> and T is that Class<T> represents metadata about T. You can look up T's methods and fields, and also create new instances by calling newInstance method.

As far as creating Class<T> objects goes, the simplest approach is to use MyClass.class syntax, e.g.

Class<TermlistRequest> tr = TermlistRequest.class;

Class (but not Class<T>) objects can also be obtained by resolving classes dynamically.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download