我有以下法典:
public class direction do(direction)
if(istrue) {
left = do(left);
} else {
right = do(right);
}
}
我很想知道,是否有办法缩短这一期限。 我尝试使用私人经营者,但有一些困难。 建议
我有以下法典:
public class direction do(direction)
if(istrue) {
left = do(left);
} else {
right = do(right);
}
}
我很想知道,是否有办法缩短这一期限。 我尝试使用私人经营者,但有一些困难。 建议
举例来说,对经营人没有明智的使用。
Java(和其他类似C的语文)的客座操作员的价值是,操作员的演讲是expression,而发言是statement。 言论产生价值,但声明不是。 如果你不使用由私人经营人expression<>em>产生的价值,那么你就没有使用私人经营人的商业。 做不到。
For your interest, here s an example of a valid use of the ternary operator:
int max(int x, int y) {
return x > y? x : y;
}
You might use a ternary expression if the other programmers on your team don t mind. So if your example were in valid Java:
public void Do(Direction direction)
{
(istrue)? left = Do(left) : right = Do(right);
}
You could omit the braces in the if
:
public void Do(Direction direction)
{
if ( istrue )
left = Do(left);
else
right = Do(right);
}
Or you even could have a one liner:
public void Do(Direction d) { (istrue)? left = Do(left) : right = Do(right); }
Above all, choose a style that s clear and not too clever. Use more lines if they make your code easier to read and understand.
通常有一线人可以读懂,但在某些情形下(对我而言),特别是如果你有非常相似的小方法的家庭:
public String getFirstName() { return first_name; }
public String getLastName() { return last_name; }
public String getAddress1() { return address1; }
public String getAddress2() { return address2; }
public String getCity() { return city; }
public String getState() { return state; }
public String getZip() { return zip; }
您的代码要求您根据具体情况将两种不同的变量(left
或right/code>)加以分配。 一种永恒的表述赢得你们的帮助,因为它不能在任务左侧使用。
That leaves the RHS of the (two) assignments. While you could in theory use a ternary expression, it will probably make the code longer.
因此,简短的答案是,一名私人经营人获得了一定帮助。
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...