從這個問題的討論How is access for private variables implemented in C++ under the hood?我提出了一個變化:不是訪問私有數據成員,可以通過投射和依賴佈局兼容性來調用私有成員函數嗎? 一些代碼 #include <iostream>
class X
{
public:
X() : private_(1) { /*..
讓我們以下面的代碼: public class Test {
class A {
public A() {}
private void testMethod() {
System.out.println("A");
}
}
class B extends A {
public B() { super(
對於公共方法調用,EasyMock的capture()允許您攔截&檢查傳遞給該方法的參數。對於私人方法調用,PowerMock的expectPrivate可以讓你模擬私人方法調用。 有沒有辦法以某種方式組合這些並獲得傳遞給私人方法調用的參數?例如: public class Program
{
public FancyReturnType PublicMethod()
{