Skip to main content

Practice ยท 2 of 3

The identity matrix

Implement four static predicates โ€” each must use == (identity), not equals: 1. static boolean pooledLiterals() โ€” is "jvm" == "jvm" (two literals)? 2. static boolean newStringSameAsLiteral() โ€” is new String("jvm") == "jvm"? 3. static boolean internedMatches() โ€” is new String("jvm").intern() == "jvm"? 4. static boolean boxCacheHolds() โ€” is Integer.valueOf(127) == Integer.valueOf(127)? 5. static boolean boxCacheMisses() โ€” is Integer.valueOf(128) == Integer.valueOf(128)? 6. static boolean bigBoxSame() โ€” is Integer.valueOf(1000) == Integer.valueOf(1000)? Return the *actual* results, whatever they are โ€” the tests know the truth.

Difficulty: advanced

Back to lesson: Practice: JVM observable drills