public GetMethod_Example() {
super();
}
public void setValue( int value ) {
this .value = value;
}
public int getValue() {
return value;
}
private int value;
public static void main( String[] args ){
try {
Method method = GetMethod_Example.class.getMethod( "getValue", new Class[] { Void.class } );
GetMethod_Example obj = new GetMethod_Example();
method.invoke( obj, new Object[] { new Integer( 1 ) } );
System.out.println( obj.getValue() );
} catch (IllegalAccessException e) {
System.out.println( "Can't access private method 'getValue'" );
} catch (InvocationTargetException e) {
System.out.println( "Problem calling method" );
} catch (NoSuchMethodException e) {
System.out.println( "No method getValue" );
}
}
|
|