@PrivateApi public final class ClassLoaderUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
HAZELCAST_ARRAY |
static String |
HAZELCAST_BASE_PACKAGE |
Modifier and Type | Method and Description |
---|---|
static Class<?>[] |
getAllInterfaces(Class<?> clazz) |
static <T> T |
getOrCreate(T instance,
ClassLoader classLoader,
String className)
Returns the
instance , if not null, or constructs a new instance of the class using
newInstance(ClassLoader, String) . |
static boolean |
implementsInterfaceWithSameName(Class<?> clazz,
Class<?> iface)
Check whether given class implements an interface with the same name.
|
static boolean |
isClassAvailable(ClassLoader classLoader,
String className) |
static boolean |
isClassDefined(String className)
Indicates whether or not the given class exists
|
static boolean |
isInternalType(Class type) |
static Class<?> |
loadClass(ClassLoader classLoaderHint,
String className) |
static <T> T |
newInstance(ClassLoader classLoaderHint,
String className)
Creates a new instance of class with
className , using the no-arg
constructor. |
static Class<?> |
tryLoadClass(String className)
Tries to load the given class.
|
public static final String HAZELCAST_BASE_PACKAGE
public static final String HAZELCAST_ARRAY
public static <T> T getOrCreate(T instance, ClassLoader classLoader, String className)
instance
, if not null, or constructs a new instance of the class using
newInstance(ClassLoader, String)
.instance
- the instance of the class, can be nullclassLoader
- the classloader used for class instantiationclassName
- the name of the class being constructed. If null, null is returned.instance
or a newly constructed instance of className
or null, if className
was nullpublic static <T> T newInstance(ClassLoader classLoaderHint, String className) throws Exception
className
, using the no-arg
constructor. Preferably uses the class loader specified in classLoaderHint
. A constructor cache is used to reduce reflection
calls.
The implementation first chooses candidate class loaders. Then checks
the constructor cache if a constructor is found for either of them. If
not, it queries them and caches the used Constructor
under the
classloader key that was used to retrieve it (might not the actual
classloader that loaded the returned instance, but a parent one). To
choose the candidate class loaders, a peculiar,
hard-to-explain-more-simply-than-reading-the-code logic is used, beware.
classLoaderHint
- Suggested class loader to use, can be nullclassName
- Class name (can be also primitive name or array
("[Lpkg.Class]"), requiredException
- ClassNotFoundException, IllegalAccessException,
InstantiationException, or InvocationTargetExceptionpublic static Class<?> loadClass(ClassLoader classLoaderHint, String className) throws ClassNotFoundException
ClassNotFoundException
public static boolean isClassAvailable(ClassLoader classLoader, String className)
public static boolean isInternalType(Class type)
public static Class<?> tryLoadClass(String className) throws ClassNotFoundException
className
- Name of the class to loadClassNotFoundException
- when the class is not foundpublic static boolean isClassDefined(String className)
className
- Name of the classtrue
if the class exists, false
otherwisepublic static boolean implementsInterfaceWithSameName(Class<?> clazz, Class<?> iface)
clazz
- class to check whether implements the interfaceiface
- interface to be implementedtrue
when the class implements the inteface with the same nameCopyright © 2020 Hazelcast, Inc.. All Rights Reserved.