๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/JAVA

[JAVA] ์ ‘๊ทผ์ œํ•œ์ž๊ฐ€ private์ธ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•

by ynzu๐Ÿค 2022. 10. 13.
๋ฐ˜์‘ํ˜•

์ฃผ๋ฌธ๋ฒˆํ˜ธ๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๊ฐ–๋Š” Order ํด๋ž˜์Šค์˜ canCancel ๋ฉ”์†Œ๋“œ๊ฐ€ private๋กœ ์„ ์–ธ๋˜์–ด ์žˆ์„ ๋•Œ

์ด ๋ฉ”์†Œ๋“œ๋ฅผ ์™ธ๋ถ€์—์„œ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

Order order = new Order();
Method method = order.getClass().getDeclaredMethod("canCancel", Order.class);
method.setAccessible(true);
boolean result = (boolean)method.invoke(order, "์ฃผ๋ฌธ๋ฒˆํ˜ธ");

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€