2016-11-10 72 views
-1

爲什麼構造函數RegisterProxy()在我們調用「R response = proxy.CallAPISync(request);」時沒有執行; ?爲什麼構造函數沒有執行?

public class SoaCaller { 
    private static RegisterProxy proxy = new RegisterProxy(); ; 
    public static <T, R> R CallAPISyn(T request){ 
     R response = proxy.CallAPISync(request); 
     return response; 
    } 
} 

public class RegisterProxy { 
    private static HashMap<String, BaseSoaImplement> cache = new HashMap<>(); 
    public RegisterProxy(){ 
     try { 
        cache.put(GetHotelStaticInfoRequestType.class.getName(), new GetHotelStaticInfoImpl()); 
    } 
catch (Exception ex){ 
     ExceptionUtils.getStackTrace(ex)); 
     } 
} 
+1

要早得多因爲這不會創建新的實例。當SoaCaller被加載時,構造函數被調用。 –

+0

構造函數將只在對象創建時被調用。 –

+0

我唯一的解釋就是它之前被調用過。 – dasblinkenlight

回答

1

new RegisterProxy();只有跑了第一次類加載器遇到類SoaCaller

這可能比調用CallAPISyn

相關問題