Cooli Cooli - 6 months ago 8x
Java Question

Java basics about generics and reflection

I am having a basic java question as I recently decided to dig into the language (I have been working exclusively with C++ for a long time and decided to expand my horizons a bit).

Assuming that I have a class called BankAccount and I try to create and object in my main, what is the difference between:

Class baCls = BankAccount.class;


Class<BankAccount> baCls = BankAccount.class;

What does the baCls hold in each of the cases and what is the compiler output?


In both cases baCls is a reference to the class BankAccount

The generic adds a compile time check but has no impact at runtime.

You can see the bytecode generated if you use javap -c -p or a byte code viewer in your IDE.