Class Classes
- java.lang.Object
-
- dk.cloudcreate.essentials.shared.reflection.Classes
-
-
Constructor Summary
Constructors Constructor Description Classes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcompareTypeSpecificity(Class<?> leftSide, Class<?> rightSide)ComparesleftSidewith therightSidefor inheritance order.
It returns: negative integer - if the leftSide is less specific then the rightSide
Example: If leftSide is a CharSequence and rightSide is a String (a specialization of CharSequence). zero - if the leftSide is equally specific to rightSide (i.e.static booleandoesClassExistOnClasspath(String fullyQualifiedClassName)Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpathstatic booleandoesClassExistOnClasspath(String fullyQualifiedClassName, ClassLoader classLoader)Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpathstatic Class<?>forName(String fullyQualifiedClassName)Load a class based on a fully qualified class name (FQCN)static Class<?>forName(String fullyQualifiedClassName, ClassLoader classLoader)Load a class based on a fully qualified class name (FQCN) and using a specificClassLoaderstatic List<Class<?>>superClasses(Class<?> type)Get all superclasses of a type.
-
-
-
Method Detail
-
forName
public static Class<?> forName(String fullyQualifiedClassName) throws ReflectionException
Load a class based on a fully qualified class name (FQCN)- Parameters:
fullyQualifiedClassName- the Fully Qualified Class Name (FQCN) as a- Returns:
- The class loaded
- Throws:
ReflectionException- in case loading the class failed
-
forName
public static Class<?> forName(String fullyQualifiedClassName, ClassLoader classLoader) throws ReflectionException
Load a class based on a fully qualified class name (FQCN) and using a specificClassLoader- Parameters:
fullyQualifiedClassName- the Fully Qualified Class Name (FQCN) as a stringclassLoader- the class loader to use- Returns:
- The class loaded
- Throws:
ReflectionException- in case loading the class failed
-
compareTypeSpecificity
public static int compareTypeSpecificity(Class<?> leftSide, Class<?> rightSide)
ComparesleftSidewith therightSidefor inheritance order.
It returns:- negative integer - if the leftSide is less specific then the rightSide
Example: If leftSide is a CharSequence and rightSide is a String (a specialization of CharSequence). - zero - if the leftSide is equally specific to rightSide (i.e. leftSide and rightSide are the same class)
Example: If leftSide is a CharSequence and rightSide is a CharSequence - negative integer - if the leftSide is more specific then the rightSide
Example: If leftSide is a String (a subclass of CharSequence) and rightSide is a CharSequence.
- Parameters:
leftSide- the left side typerightSide- the right side type- Returns:
- the inheritance comparison between the leftSide and rightSide
- Throws:
IllegalArgumentException- in case leftSide and rightSide aren't either the same class or in a inheritance hierarchy with each other
- negative integer - if the leftSide is less specific then the rightSide
-
superClasses
public static List<Class<?>> superClasses(Class<?> type)
Get all superclasses of a type.- Parameters:
type- The type to get all super classes for- Returns:
- All superclasses of
type
-
doesClassExistOnClasspath
public static boolean doesClassExistOnClasspath(String fullyQualifiedClassName)
Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpath- Parameters:
fullyQualifiedClassName- the fully qualified name of the class- Returns:
- true if a class with the given Fully Qualified Class Name (FQCN) exists on the classpath, otherwise false
-
doesClassExistOnClasspath
public static boolean doesClassExistOnClasspath(String fullyQualifiedClassName, ClassLoader classLoader)
Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpath- Parameters:
fullyQualifiedClassName- the fully qualified name of the classclassLoader- the classloader used to check if the class exist- Returns:
- true if a class with the given Fully Qualified Class Name (FQCN) exists on the classpath, otherwise false
-
-