java 的关键字参数?你怎么认为?
这实际上不是一个可以回答的问题,而是一个“你觉得怎么样”的问题。
在 python 中,程序员可以选择在函数调用中使用关键字参数。例如,
def doSomething(test=True, numBacon=5, ...):
除了我之外,还有谁认为这对 Java 来说是一个奇妙的想法吗?我知道可变参数可以做很多事情,但它并不像关键字参数那么有用。所以我问全世界,你们怎么看?
This really isn't so much an answerable question as a 'What do you think' question.
In python, the programmer has the option to use keywords arguments in their function calls. For example
def doSomething(test=True, numBacon=5, ...):
Does any one other than me think that would be a fantasic idea for java? I know that varargs can do a lot, but it doesn't come close to being as useful are keyword arguments. So I ask the world, what do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能 - 如果您可以将映射传递到方法中,该方法将查找映射的键控条目。它将需要一个内联的、无类型的映射声明,这在这种有限的范围之外不会很有用——而且由于它非常有限,我最终会说“不,不需要”。如果您需要这种便利,请使用 Python。如果您想要 JVM 中的功能,请使用 Jython 或 JRuby。
It might - if you could pass a map into a method, which would look up the map's keyed entries. It would require an inline, typeless map declaration, which wouldn't be very useful outside of this kind of limited scope - and since it'd be very limited, I'd end up saying "No, not required." If you want the facility, use Python. If you want the capability in a JVM, use Jython or JRuby.