SMSLib 3.5.3

org.smslib.helper
Class ReflectionHelper

java.lang.Object
  extended by org.smslib.helper.ReflectionHelper

public class ReflectionHelper
extends java.lang.Object

Some methods to use generics with reflection.


Constructor Summary
ReflectionHelper()
           
 
Method Summary
static java.lang.reflect.Method getMethodOnlyByName(java.lang.Class<?> c, java.lang.String methodName)
          Searches in the given class for the given method name.
static
<T> T
invokeAndCast(T returnType, java.lang.reflect.Method m, java.lang.Object obj, java.lang.Object... args)
          Invokes the given method on the given object with the given arguments.
static
<T> java.util.Collection<T>
invokeAndCastCollection(T returnType, java.lang.reflect.Method m, java.lang.Object obj, java.lang.Object... args)
          Same as but with a cast to Collection
static
<T> java.util.Enumeration<T>
invokeAndCastEnumeration(T returnType, java.lang.reflect.Method m, java.lang.Object obj, java.lang.Object... args)
          Same as but with a cast to Enumeration
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionHelper

public ReflectionHelper()
Method Detail

getMethodOnlyByName

public static java.lang.reflect.Method getMethodOnlyByName(java.lang.Class<?> c,
                                                           java.lang.String methodName)
                                                    throws java.lang.NoSuchMethodException
Searches in the given class for the given method name. The argument list is ignored. Overload methods shouldn't used with it - You can't be sure which method you will get!

Parameters:
c - Class to search
methodName - Methodname to search
Returns:
The found method
Throws:
java.lang.NoSuchMethodException - If the search method isn't shown

invokeAndCast

public static <T> T invokeAndCast(T returnType,
                                  java.lang.reflect.Method m,
                                  java.lang.Object obj,
                                  java.lang.Object... args)
Invokes the given method on the given object with the given arguments. The result is cast to T and every kind of exception is wrapped as RuntimeException


invokeAndCastEnumeration

public static <T> java.util.Enumeration<T> invokeAndCastEnumeration(T returnType,
                                                                    java.lang.reflect.Method m,
                                                                    java.lang.Object obj,
                                                                    java.lang.Object... args)
Same as but with a cast to Enumeration

See Also:
invokeAndCast(Object, Method, Object, Object...)

invokeAndCastCollection

public static <T> java.util.Collection<T> invokeAndCastCollection(T returnType,
                                                                  java.lang.reflect.Method m,
                                                                  java.lang.Object obj,
                                                                  java.lang.Object... args)
Same as but with a cast to Collection

See Also:
invokeAndCast(Object, Method, Object, Object...)

SMSLib 3.5.3

(c) 2002-2011, http://smslib.org