如何始终返回 java.util.Vector
如果我的控件中的值只有一个值,则以下代码将返回一个字符串,如果有多个值,则代码将返回一个 java.util.Vector。
getComponent("mycontrol").getValue();
我希望这段代码返回一个向量,即使只有一个值。
我已经看到了几个将字符串转换为数组的代码片段,但我想取回一个向量。
If the value in my control only have one value the following code will return a String, if there are more than one value the code will return a java.util.Vector.
getComponent("mycontrol").getValue();
I want this code to return a vector even if there is only one value.
I have seen several code snippets that converts my string to an Array, but I want to get back a vector.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有办法强制将奇异值作为 java.util.vector (或就此而言的数组)返回。唯一的方法是测试它是否是一个向量,如果不是,则构建一个向量。您可以将其放入一个函数中并将调用包装到其中...例如(这是未经测试的代码,因此您需要验证语法等):
There is no way to force a singular value to be returned as a java.util.vector (or Array for that matter). The only way would be to test to see if it is a vector, then build a vector if not. You could place it into a function and wrap the call into that... for example (this is untested code so you'll need to verify syntax, etc):