switch versus if ... else if ... else
No. 235
|
Q: |
Consider a method
This method will be called by two different implementations
of another method
An experienced programmer claims these two implementations
possibly return different results when executing
TipHow often is |
||||
|
A: |
The difference between both implementations is about calling
public class X {
private static int itemCount = 2;
static int advanceItemCount() {return itemCount++;}
...
public static int getScore() {/* either »switch« or »if« implementation */}
}On a fresh start the “ On contrary the “if” implementation will call
For aligning both implementations we require a small modification on the “if” implementation: |
