看教程,編寫例子時,爲了偷懶方便,在下面直接添加了一個類。由於沒注意}的問題,寫的是內部類。
結果創建後發生:No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).編譯錯誤。
所以解決辦法。
1. 添加static 從內部類變成靜態內部類
2.在創建之時以外部類().new 內部類()
雖然是自己疏忽,但是還是算踩坑了吧,記錄一下~