This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
你的两条指令在 if 两边都是一样的!我怀疑你粘贴错了东西。让我们假设它们是不同的(
"Y"
和"N"
):) 您可以简单地使用 三元运算符:编辑:从您的评论来看,您似乎确实想将值设置为 'N ' 每次?在这种情况下,您根本不需要
if
...Your two instructions are the same on both sides of the if! I suspect you pasted something wrong. Let's assume they're different (
"Y"
and"N"
) :) You can write it simply using the ternary operator:EDIT: From your comments, it seems like you actually want to set the value to 'N' every time? In that case, you don't need the
if
at all...如果我们可以假设您在新的java中使用某种集合,那么这样的东西会更简洁并且不会因空指针而崩溃?
If we can assume that you are using a Collection of some sort in the new java, something like this would be more concise and won't crash due to null pointers?
三元条件语句就可以了。
Ternary conditional statement would be fine.
假设您从列表之类的地方获取迭代器:
如果是这种情况(并且它或类似的东西几乎必须是这种情况),那么您可以完全放弃迭代器并使您的代码更易于阅读, 因此:
Let's assume you're getting your iterator from somewhere like a List:
If that's the case (and it, or something like it, almost has to be the case), then you can forgo the iterator entirely and make your code much easier to read, thus: