0

It's a bit wired when init Lrucache, it throws NullPointerException.

The code is:

 @Test
fun testLruCache() {
    try {
        val code = "code"
        val cache: LruCache<String, Int> = LruCache(1000)
        println(cache)
        Assert.assertNotNull(cache)
        cache.put(code, 1)
        val getValue = cache.get(code)
        Assert.assertEquals(1, getValue)
        println("try end")
    } catch (e: Exception) {
        println(e)
        println("catch end")
    }
}

And the output is:

java.lang.NullPointerException
catch end

enter image description here

The line println(cache) even without called, the LruCache throw the exception. So does the behavior in unit test is different?

William Hu
  • 15,423
  • 11
  • 100
  • 121

0 Answers0