Package com.google.common.reflect
Class Reflection
- java.lang.Object
-
- com.google.common.reflect.Reflection
-
public final class Reflection extends java.lang.Object
Static utilities relating to Java reflection.- Since:
- 12.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
getPackageName(java.lang.Class<?> clazz)
Returns the package name ofclazz
according to the Java Language Specification (section 6.7).static java.lang.String
getPackageName(java.lang.String classFullName)
Returns the package name ofclassFullName
according to the Java Language Specification (section 6.7).static void
initialize(java.lang.Class<?>... classes)
Ensures that the given classes are initialized, as described in JLS Section 12.4.2.static <T> T
newProxy(java.lang.Class<T> interfaceType, java.lang.reflect.InvocationHandler handler)
Returns a proxy instance that implementsinterfaceType
by dispatching method invocations tohandler
.
-
-
-
Method Detail
-
getPackageName
public static java.lang.String getPackageName(java.lang.Class<?> clazz)
Returns the package name ofclazz
according to the Java Language Specification (section 6.7). UnlikeClass.getPackage()
, this method only parses the class name, without attempting to define thePackage
and hence load files.
-
getPackageName
public static java.lang.String getPackageName(java.lang.String classFullName)
Returns the package name ofclassFullName
according to the Java Language Specification (section 6.7). UnlikeClass.getPackage()
, this method only parses the class name, without attempting to define thePackage
and hence load files.
-
initialize
public static void initialize(java.lang.Class<?>... classes)
Ensures that the given classes are initialized, as described in JLS Section 12.4.2.WARNING: Normally it's a smell if a class needs to be explicitly initialized, because static state hurts system maintainability and testability. In cases when you have no choice while interoperating with a legacy framework, this method helps to keep the code less ugly.
- Throws:
java.lang.ExceptionInInitializerError
- if an exception is thrown during initialization of a class
-
newProxy
public static <T> T newProxy(java.lang.Class<T> interfaceType, java.lang.reflect.InvocationHandler handler)
Returns a proxy instance that implementsinterfaceType
by dispatching method invocations tohandler
. The class loader ofinterfaceType
will be used to define the proxy class. To implement multiple interfaces or specify a class loader, useProxy.newProxyInstance(java.lang.ClassLoader, java.lang.Class<?>[], java.lang.reflect.InvocationHandler)
.- Throws:
java.lang.IllegalArgumentException
- ifinterfaceType
does not specify the type of a Java interface
-
-