public GetDeclaredMethod_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 = GetDeclaredMethod_Example.class.getDeclaredMethod( "getValue", new Class[] { Void.class } );
GetDeclaredMethod_Example obj = new GetDeclaredMethod_Example();
method.invoke( obj, new Object[] { new Integer( 1 ) } );
System.out.println( obj.getValue() );
} catch (IllegalAccessException e) {
System.out.println( "Nie można uzyskać dostępu do prywatnej metody getValue" );
} catch (InvocationTargetException e) {
System.out.println( "Problem przy wywoływaniu metody" );
} catch (NoSuchMethodException e) {
System.out.println( "Brak metody getValue" );
}
}
|
|