Compare class objects

Posted by reto on Stack Overflow See other posts from Stack Overflow or by reto
Published on 2010-04-15T16:43:19Z Indexed on 2010/04/15 16:53 UTC
Read the original article Hit count: 223

Filed under:

I have to compare a class object against a list of pre defined classes. Is it safe to use == or should I use equals()?

if        (klass == KlassA.class) {
} else if (klass == KlassB.class) {
} else if (klass == KlassC.class) {
} else {
}

Note: I cannot use instanceof, I don't have an object, I just have the class object. I (mis)use it like an enum in this situation!

Thanks!

© Stack Overflow or respective owner

Related posts about java