Why is assert used in the Integer.valueOf method of the Integer class?
I was digging into how the Integer class actually uses cached objects, and I found the below code in the Integer.valueOf method: public static Integer valueOf(int i) { assert IntegerCache.high >= 127; if (i >= IntegerCache.low && i <= IntegerCache.high) return IntegerCache.cache[i + (-IntegerCache.low)]; return new Integer(i); } My question is: what is the use of assert IntegerCache.high >= 127; I read that assert provides an effective way to detect and correct programming errors . But this is runtime code so why would someone use assert? And when will it throw AssertionError in this scenario?