[問題] interface的使用? @inject的使用?

看板java作者 (oopp)時間14年前 (2011/08/10 08:59), 編輯推噓3(304)
留言7則, 4人參與, 最新討論串1/1
public class WorkbenchPresenter implements WorkbenchViewImpl.Presenter { @Inject protected BrowserView.Presenter browserPresenter; 略 public void init(){ browserPresenter.init(); } 略 } public interface BrowserView extends View<BrowserView.Presenter> { public interface Presenter { void init(); } } 想請教一下, 宣告了一個interface但是卻沒有implement它,直接使用interface的methoed ,我的想法這樣應該是不行的吧,應該是要有一個implement interace的子類別在等號的 右邊吧,請問有什麼可能能讓這段程式成立呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.146.83.112 ※ 編輯: b6byc 來自: 122.146.83.112 (08/10 17:00)

08/10 20:12, , 1F
brosePresenter = new CPresenter();
08/10 20:12, 1F

08/10 20:13, , 2F
其中的CPresenter是class implement BrowserView.Presene
08/10 20:13, 2F

08/10 20:14, , 3F
這樣吧? 話說cd時間怎麼1分鐘這麼久= =
08/10 20:14, 3F
我想應該是這樣沒錯,不過程式碼裡沒有new,我也很納悶. ※ 編輯: b6byc 來自: 119.77.212.164 (08/10 23:47)

08/10 23:53, , 4F
這個程式碼是你在書裡看到的嗎? 會不會只是部分?
08/10 23:53, 4F

08/11 00:33, , 5F
你想要知道的事,應是「@Inject」究竟做了什麼...
08/11 00:33, 5F
http://download.oracle.com/javaee/6/api/javax/inject/package-summary.html @Inject Identifies injectable constructors, methods, and fields. 所以在java ee 6裡,自己就會辨識到method(在原程式碼是有implement,但我不懂如何 連接上的),感覺上真是神奇... ※ 編輯: b6byc 來自: 122.146.83.112 (08/11 10:08)

08/11 10:05, , 6F
樓上很smart
08/11 10:05, 6F

08/11 16:42, , 7F
實在看不懂 @Inject 到底做了什麼…
08/11 16:42, 7F
文章代碼(AID): #1EGaY9xi (java)