vendredi 2 octobre 2015

How to compare classes with primitive type classes? [duplicate]

This question already has an answer here:

Since Class does not implement Comparable I use the following method to test two classes:

public int compare(Class o1, Class o2) {
    return o1.isAssignableFrom(o2) && o2.isAssignableFrom(o1) ?
        0 :
        o1.getName().compareTo(o2.getName());
}

I'd expect compare(float.class, Float.class) == 0 or compare(int.class, Integer.class) == 0; how to do that without checking explicitly for certain types?





Aucun commentaire:

Enregistrer un commentaire