class MyCastingClass { public Object myMethod() { String myString = "Some data"; Object myObj = (Object) myString; return myObj; } }
class MyCastingClass { public Object myMethod() { return "Some data"; } }
int someNumber = (someValue * number1 / number2) + otherValue; int someNumber2 = (someValue * number1 / number2) +
final int constantCalculation = (someValue * number1 / number2); int someNumber = (constantCalculation) + otherValue; int someNumber2 = (constantCalculation) + otherValue2;
class MyStringClass { public void myMethod() { String myString = "Some data"; for (int i = 0; i < 20; i++) { myString += getMoreChars(); } } }
class MyCastingClass { public Object myMethod() { String myString = "Some data"; StringBuffer myBuffer = new StringBuffer(); for (int i = 0; i < 20; i++) { myBuffer.append(getMoreChars()); } myString = myBuffer.toString(); } }
4. Use Short Circuit Boolean Operators
class MyShortCircuitClass { public void myMethod() { if (someValue.equals("true") | someValue.equals("false")) { System.out.println("valid boolean"); } } }
class MyCastingClass { public void myMethod() { if ("true".equals(someValue) || "false".equals(someValue)) { System.out.println("valid boolean"); } } }
Here’s a table describing four of Java’s boolean operators:
Meaning | Short circuit? | |
---|---|---|
&& | and | yes |
& | and | no |
|| | or | yes |
| | or | no |
class MyStringClass {
public boolean myTestMethod() { return myString.equals(""); } }
class MyCastingClass { public void myMethod() { public boolean myTestMethod() { // which really does myString.length() == 0 behind the schenes return myString.isEmpty(); } } }
아파치 + 톰켓 연동 (0) | 2012.02.02 |
---|---|
우분투에 VSFTP 설치하기 (0) | 2012.01.14 |
AXIS2 예제 사이트 (0) | 2011.11.10 |