Skip to main content

Practice · 2 of 3

The identity matrix

CHALLENGE
Difficulty: advanced+25 XP

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.

Back to lesson: Practice: JVM observable drills