2011-06-24 27 views
1

我撿了別人的工作,這讓我不解:瞭解GWT.create()的Java接口

了2接口

public interface WebAuthenticationServiceAsync { 
void authenticate(String userName, String password, AsyncCallback callback);} 

public interface WebAuthenticationService extends RemoteService { 
ArrayList authenticate(String userName, String password); } 

有實現那些在沒有課整個項目

,然後我得到:

authenticationService = (WebAuthenticationServiceAsync)GWT.create(WebAuthenticationService.class); 

1 .-我明白.create ()是GWT的反射機制,但都是接口,我不知道我得到什麼或如何。

2.-我知道,鑄造替換Arraylist authenticate()與無效authenticate(),如果這就是我應該做的情況下WebAuthemticationServiceAsync擴展RemoteService,並擺脫WebAuthenticationService之一?

回答

1

這些是GWT-RPC 合同,你可以閱讀更多:http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideRemoteProcedureCalls

BTW,GWT.create()是不是反映,它是關於用另一個替換類型(比如,你有一個基本實現,這可以是具體的或抽象的類,也可以是接口,例如Internet Explorer,您可以使用特定的實現)或生成一個類型。後一種情況是GWT-RPC:接口的實現將在編譯時生成並用於代替GWT.create()調用。 在http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html

+0

瞭解更多關於「延遲綁定」(即在編譯時而不是「編碼時間」綁定實際類型)謝謝,看到一個圖總是讓事情變得更加清晰:) – javaNoober