java.lang.Object
java.lang.reflect.AccessibleObject
java.lang.reflect.Method
- All Implemented Interfaces:
- AnnotatedElement, GenericDeclaration, Member
- See Also:
- Top Examples, Source Code,
Class
,
Class.getMethods()
,
Class.getMethod(String, Class[])
,
Class.getDeclaredMethods()
,
Class.getDeclaredMethod(String Class[])
public boolean equals(Object obj)
- See Also:
Hashtable
, Object.hashCode()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
- See Also:
- AccessibleObject, AnnotatedElement
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Annotation[] getDeclaredAnnotations()
- See Also:
- AccessibleObject, AnnotatedElement
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Class<?> getDeclaringClass()
- See Also:
- Member
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Object getDefaultValue()
- See Also:
Class
, TypeNotPresentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Class<?>[] getExceptionTypes()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Type[] getGenericExceptionTypes()
- See Also:
- MalformedParameterizedTypeException, TypeNotPresentException, GenericSignatureFormatError
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Type[] getGenericParameterTypes()
- See Also:
- MalformedParameterizedTypeException, TypeNotPresentException, GenericSignatureFormatError
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Type getGenericReturnType()
- See Also:
- MalformedParameterizedTypeException, TypeNotPresentException, GenericSignatureFormatError
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int getModifiers()
- See Also:
Modifier
, Member
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String getName()
- See Also:
- Member
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Annotation[][] getParameterAnnotations()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Class<?>[] getParameterTypes()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Class<?> getReturnType()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public TypeVariable<Method>[] getTypeParameters()
- See Also:
- GenericSignatureFormatError, GenericDeclaration
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int hashCode()
- See Also:
Hashtable
, Object.equals(java.lang.Object)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Object invoke(Object obj,
Object... args)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException
- See Also:
- ExceptionInInitializerError, NullPointerException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Object invoke(Object obj,
Object[] args)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException
- See Also:
- ExceptionInInitializerError, NullPointerException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[119]Invoke zero-argument method through reflection
By Anonymous on 2002/11/04 17:51:29 Rate
public void actionPerformed ( ActionEvent ev ) {
try {
Method m = getClass ( ) .getMethod ( getActionCommand ( ) , new Class [ 0 ] ) ;
m.invoke ( this,new Object [ 0 ] ) ;
}
catch ( Exception ex ) {
}
}
[928]Demonstrate static methods through reflection
By Anonymous on 2004/09/25 22:22:55 Rate
import java.lang.reflect.Method;
public class Testsomething
{
public static void main ( String [ ] args ) throws Exception
{
TestMethod test = new TestSubMethod ( ) ;
test.doSomething ( ) ; //OUTPUT: TestMethod.doSomething
TestSubMethod sub = new TestSubMethod ( ) ;
sub.doSomething ( ) ; //OUTPUT: TestSubMethod.doSomething
( ( TestMethod ) sub ) .doSomething ( ) ; //OUTPUT: TestMethod.doSomething
Method method = TestMethod.class.getDeclaredMethod ( "doSomething", null ) ;
method.invoke ( sub, null ) ; //OUTPUT: TestMethod.doSomething
method.invoke ( test, null ) ; //OUTPUT: TestMethod.doSomething
method.invoke ( null, null ) ; //OUTPUT: TestMethod.doSomething
Method subMethod = TestSubMethod.class.getDeclaredMethod ( "doSomething", null ) ;
subMethod.invoke ( sub, null ) ; //OUTPUT: TestSubMethod.doSomething
subMethod.invoke ( test, null ) ; //OUTPUT: TestSubMethod.doSomething
subMethod.invoke ( null, null ) ; //OUTPUT: TestSubMethod.doSomething
}
}
class TestMethod
{
static void doSomething ( )
{
System.out.println ( "TestMethod.doSomething ( ) " ) ;
}
}
class TestSubMethod extends TestMethod
{
static void doSomething ( )
{
System.out.println ( "TestSubMethod.doSomething" ) ;
}
}
[1714]The use of reflection on a method with array type parameters
By Edson Wunderlich on 2006/02/17 16:12:54 Rate
import java.lang.reflect.Method;
public class TestMethodReflection
{
public static void main ( String [ ] args ) throws Exception
{
TestMethodReflection thisClass = new TestMethodReflection ( ) ;
String methodName;
Class [ ] methodParametersList;
Object [ ] methodParametersValues;
Method method;
// Invoking a non-static method using reflection
//
methodName = "nonStaticMethod";
methodParametersList = new Class [ ] { String [ ] .class, long.class } ;
System.out.println ( "--- Invoking a non-static method using reflection ---\n" ) ;
method = TestMethodReflection.class.getMethod ( methodName,methodParametersList ) ;
methodParametersValues = new Object [ ] { new String [ ] { "Non-static method called using reflection", "2nd String of 3", "3rd String of 3" } , 2006 } ;
method.invoke ( thisClass,methodParametersValues ) ;
// Invoking a static method using reflection
//
methodName = "staticMethod";
methodParametersList = new Class [ ] { String [ ] .class, long.class } ;
methodParametersValues = new Object [ ] { new String [ ] { "Static method called using reflection", "2nd String of 3", "3rd String of 3" } , 2006 } ;
method = TestMethodReflection.class.getMethod ( methodName,methodParametersList ) ;
System.out.println ( "\n--- Invoking a static method using reflection ---\n" ) ;
method.invoke ( TestMethodReflection.class, methodParametersValues ) ;
//method.invoke ( new Object ( ) , methodParametersValues ) ; //works fine
//method.invoke ( 1, methodParametersValues ) ; //works perfectly
//method.invoke ( null, methodParametersValues ) ; //works just as fine
}
private static void processMethodParameters ( String callingMethod, String [ ] strings, long longValue )
{
String ident = "Parameter values: ";
System.out.println ( "Method..........: \"" + callingMethod + "\"" + ( ( strings.length > 0 ) ? " ( " + strings [ 0 ] + " ) " : "" ) ) ;
System.out.println ( "Parameters types: strings [ 0.."+ ( strings.length-1 ) +" ] ( Quantity=" + strings.length + " ) " ) ;
System.out.println ( "Parameters types: long" ) ;
for ( int i = 0; i < strings.length; i++ )
{
System.out.println ( ident + ( i + 1 ) + ". Parameter string [ " + i + " ] = \"" + strings [ i ] + "\"" ) ;
}
System.out.println ( ident + ( strings.length + 1 ) + ". Parameter long..... = " + longValue ) ;
}
public static void staticMethod ( String [ ] strings, long longValue )
{
processMethodParameters ( "staticMethod", strings, longValue ) ;
}
//non-static methos must be public if they are to be called using reflection
//
public void nonStaticMethod ( String [ ] strings, long longValue )
{
processMethodParameters ( "nonStaticMethod", strings, longValue ) ;
}
}
public boolean isBridge()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean isSynthetic()
- See Also:
- Member
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean isVarArgs()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toGenericString()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toString()
- See Also:
- Object
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples