在GWT中使用泛型有好处吗
在GWT中使用java泛型对GWT编译器有什么好处吗。也就是说,它是否有助于创建更小或更高效的javascript代码,或者它是否具有与在Java中使用它们相同的好处 使用GWT、MVP和泛型会带来复杂性。。要正确实现泛型,接口如下所示:在GWT中使用泛型有好处吗,gwt,Gwt,在GWT中使用java泛型对GWT编译器有什么好处吗。也就是说,它是否有助于创建更小或更高效的javascript代码,或者它是否具有与在Java中使用它们相同的好处 使用GWT、MVP和泛型会带来复杂性。。要正确实现泛型,接口如下所示: public interface ViewInterface<P extends PresenterInterface<? extends ViewInterface<P>>> { } public interface Pr
public interface ViewInterface<P extends PresenterInterface<? extends ViewInterface<P>>> {
}
public interface PresenterInterface<V extends ViewInterface<? extends PresenterInterface<V>>> {
}
公共界面ViewInterface>{
}
公共接口Presenterface,正如Ray Ryan在使用GWT RPC时提到的那样。您可以查看演示文稿。有一个名为GAD a.k.a GWT Action Dispatcher的库,该库的思想来自于演示文稿中Rayan的推荐。GAD由5个使用泛型的组件(类和接口)组成。如果没有泛型,那么在客户端代码和服务器代码中都会有大量的类型转换,其中操作和响应实现在客户端和服务器之间共享。我上面提到的5个组件是:
1-
公共接口操作扩展了可序列化{
}
2-
公共接口ActionHandler{
/**
*处理提供的操作并重新运行其响应。
*
*@param action要处理的操作
*@return要返回的响应
*/
T手柄(K动作);
}
3-
公共接口ActionDispatcher{
/**
*将提供的操作分派给负责处理该操作的适当处理程序。
*若要分派输入操作,则需要绑定适当的处理程序
*到{@link com.evo.gad.dispatch.ActionHandlerRepository},可以使用dispatch方法分派
*向它输入请求。
*
*@param action要处理的操作
*@param是一种泛型响应类型
*@从提供的执行返回响应
*@throws-ActionHandlerNotBoundException在没有绑定处理程序来处理该操作的情况下抛出
*/
T调度(Action Action)抛出ActionHandlerNotBoundException;
}
4-
公共接口ActionHandlerRepository{
ActionHandler getActionHandler(ClassThank@Adio)感谢您的回复,我确实理解泛型的好处。当我们使用泛型实现MVP时,复杂的问题出现在GWT中……我们的接口如下所示:“我们的接口如下所示:”我看不到接口。您读过这篇文章吗
public interface ViewInterface<P extends PresenterInterface<?>> {
}
public interface PresenterInterface<V extends ViewInterface<?>> {
}
public interface Action<T extends Response> extends Serializable {
}
public interface ActionHandler<K extends Action, T extends Response> {
/**
* Handles the provided action and retuns response of it.
*
* @param action the action to be handled
* @return the response to be returned
*/
T handle(K action);
}
public interface ActionDispatcher {
/**
* Dispatches the provided action to a proper handler that is responsible for handling of that action.
* <p/> To may dispatch the incomming action a proper handler needs to be bound
* to the {@link com.evo.gad.dispatch.ActionHandlerRepository} to may the dispatch method dispatch the
* incomming request to it.
*
* @param action the action to be handled
* @param <T> a generic response type
* @return response from the provided execution
* @throws ActionHandlerNotBoundException is thrown in cases where no handler has been bound to handle that action
*/
<T extends Response> T dispatch(Action<T> action) throws ActionHandlerNotBoundException;
}
public interface ActionHandlerRepository {
ActionHandler getActionHandler(Class<? extends Action> aClass);
}