通用返回类型 - Java
我的问题是基于使用命令模式调用服务器方法。然而,有许多可能的命令。我想为每个命令实例的“执行”方法引入一个返回类型。我知道这不是命令模式的预期用途,但我别无选择。我需要定制适合我的命令模式。
对于每个命令中“执行”方法的方法签名,我可能有什么作为返回类型?我猜它必须是协变返回类型。这不是一个理想的解决方案,但我没有太多其他选择。我正在为我的 Android 应用程序开发服务器,但 Android SDK 中不提供 RMI。对于有关返回类型问题的任何建议,我将不胜感激。我需要考虑可以从所有不同命令返回的所有返回类型。我不确定是否存在针对返回某种通用返回类型的问题的模式。
我已经看过这个线程: 命令模式返回状态 但我需要更多灵感。
My question is based around invoking a server method by using the command pattern. However there are many possible commands. I would like to introduce a return type for the 'execute' method of each command instance. I know this is not the intended use of the command pattern, but I haven't any other choice. I need to tailor the command pattern to work for me.
For the method signature of the 'execute' method in each command, what could I possibly have as the return type? I'm guessing it would have to be a covariant return type. It's not an ideal solution but I haven't many other options. I'm developing a server for my android app and RMI isn't available in the Android SDK. I would appreciate any advice about the return type issue. I would need to take account of all of the return types that could be returned from all of the different commands. I'm not sure if there is a pattern out there for this issue of returning some sort of generic return type.
I have already looked at this thread:
command pattern returning status
but I need more inspiration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能不明白这里真正的问题,但这听起来很简单。
然后命令可能是:
或者有什么地方有问题吗?
I probably don't understand the real question here, but this sounds straightforward.
And then teh commands could be:
Or is there a catch somewhere?
看来您真正想要的是 RMI,而 Android 不支持它。
您可以尝试使用轻量级的RMI。
要自己实现一些东西,请从biziclop的界面开始,
It looks like what you really want is RMI, which Android doesn't support.
You can try to use a lightweight RMI.
To implement something yourself, start from biziclop's interface,