Top Description Constructors Methods
com.google.common.reflect

public final Class Reflection

extends Object
Class Inheritance
Annotations
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull

Static utilities relating to Java reflection.
Since
12.0

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String
getPackageName(Class<?> clazz)

Returns the package name of clazz according to the Java Language Specification (section 6.7).

public static String
getPackageName(String classFullName)

Returns the package name of classFullName according to the Java Language Specification (section 6.7).

public static void
initialize(Class<?>... classes)

Ensures that the given classes are initialized, as described in JLS Section 12.4.2.

public static <T> T
newProxy(Class<T> interfaceType, InvocationHandler handler)

Returns a proxy instance that implements interfaceType by dispatching method invocations to handler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Reflectionback to summary
private Reflection()

Method Detail

getPackageNameback to summary
public static String getPackageName(Class<?> clazz)

Returns the package name of clazz according to the Java Language Specification (section 6.7). Unlike Class#getPackage, this method only parses the class name, without attempting to define the Package and hence load files.

getPackageNameback to summary
public static String getPackageName(String classFullName)

Returns the package name of classFullName according to the Java Language Specification (section 6.7). Unlike Class#getPackage, this method only parses the class name, without attempting to define the Package and hence load files.

initializeback to summary
public static void initialize(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.

Exceptions
ExceptionInInitializerError:
if an exception is thrown during initialization of a class
newProxyback to summary
public static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler)

Returns a proxy instance that implements interfaceType by dispatching method invocations to handler. The class loader of interfaceType will be used to define the proxy class. To implement multiple interfaces or specify a class loader, use Proxy#newProxyInstance.

Exceptions
IllegalArgumentException:
if interfaceType does not specify the type of a Java interface