我有一個用Java編寫的應用程序。我有3個類mysql_query,tablesetup,table_action。現在在每個類的類中,我創建了其他類的對象,這會導致遞歸對象調用。我可以用什麼方法來解決這個問題?Java中的StackOverflow異常
例如:
在mysql_query.java我有
public class mysql_query{ tablesetup tablesetup = new tablesetup(); table_action table_action = new table_action(); }
在tablesetup.java我有
public class tablesetup{ mysql_query mysql_query= new mysql_query(); table_action table_action = new table_action(); }
類似地,在table_action.java我有
public class table_action{ mysql_query mysql_query= new mysql_query(); tablesetup tablesetup= new tablesetup(); }
- EDIT-- 傳遞一個類對象到其他構造函數不會在我的情況下鍛鍊,因爲我有很多像這樣的依賴類。那麼通常程序員如何安排這些類?我可以使用interface
嗎?在這種情況下使用是否合適?
似乎所有3類實例,另2作爲屬性。這是你的意圖嗎? –