¿¹Á¦

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 } ); //$NON-NLS-1$
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( "Can't access private method 'getValue'" ); //$NON-NLS-1$
} catch (InvocationTargetException e) {
System.out.println( "Problem calling method" ); //$NON-NLS-1$
} catch (NoSuchMethodException e) {
System.out.println( "No method getValue" ); //$NON-NLS-1$
}

}

¼Ö·ç¼Ç
¸Þ¼ÒµåÀÇ Çϵå ÄÚµùµÈ À̸§À» »ç¿ëÇÏ¿© getDeclaredMethod() ´ë½Å Á÷Á¢ ¸Þ¼Òµå È£ÃâÀ» »ç¿ëÇϽʽÿÀ.

public GetDeclaredMethod_Solution() {
super();
}

public void setValue( int value ) {
this .value = value;
}

public int getValue() {
return value;
}

private int value;

public static void main(String[] args) {
GetDeclaredMethod_Example obj = new GetDeclaredMethod_Example();
obj.setValue( 1 );
System.out.println( obj.getValue() );
}