Consider this:
public abstract class AbstractHibernateDao< T extends Serializable > {
private T clazz;
}
And this:
public abstract class AbstractHibernateDao< T extends Serializable > {
private Class< T > clazz;
}
I am able to compile both - so I definitely did some basic checks here.
T clazz
we expect an instance of a class, Class< T > clazz
we expect an instance of Class
which describes T
(class literal).So let's say that as T
we will use Integer
. In that case:
clazz
will allow us to store 1
, 2
, etc.Integer.class
.private T clazz;
Here clazz
can hold any type, which is of type Serializable, even your custom class object, if it is of type Serializable.
In this case, the name says it is a class (clazz
), but the value need to be Class object.
private Class< T > clazz;
Here, it is the Type of the Class
. Class is a generic type, so here clazz can hold only Class object which Type is of Serializable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With