public GetMethod_Exemplo() {
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_Exemplo.class.getMethod( "getValue", new Class[] { Void.class } );
GetMethod_Exemplo obj = new GetMethod_Exemplo();
method.invoke( obj, new
Object[] { new Integer( 1 ) } );
System.out.println( obj.getValue() );
} catch
(IllegalAccessException e) {
System.out.println( "Não é
possível acessar o método privado 'getValue'" );
} catch
(InvocationTargetException e) {
System.out.println( "Problema
ao chamar o método" );
} catch
(NoSuchMethodException e) {
System.out.println( "Nenhum
método getValue" );
}
}
|
|