Return to Snippet

Revision: 51683
at October 1, 2011 11:14 by Cur3n4


Updated Code
public static final Integer multiply(Integer x, Integer y) {
   return x * y;
}

Revision: 51682
at October 1, 2011 11:08 by Cur3n4


Initial Code
public void a() {}

Initial URL


Initial Description
The first thing to notice is that this is an extremely convoluted way of multiplying two integers. Assuming the code can be compiled using Java 5 the integers can be multiplied as below. If previous jdks versions are used then autoboxing is not available and we have to convert it into a primitive and back into an Integer, but the code will still be cleaner.

The code will fail if y is a negative value, boundary checks. There are other code style issues in the code: the code is hard to read, the y variable is modified when calling multiply, and the ternary operator doesn't help to make the code clearer.

Initial Title
Answer question 3

Initial Tags


Initial Language
Java