Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

425
Views
What‘s different between weakKeys() and weakValues() in Guava Cache?

I know weakKeys() means the keys are wrapped by WeakReference and GC may collect the keys automatically, same with weakValues()(for value).

My understanding: Once an entry (whether key or value) was collected by GC, the entry is expired.

My question:

  • Are weakKeys() and weakValues() equivalent? (one of them was collected, the entry is expired)
  • Guava doc said: "when this method is used, the resulting cache will use identity (==) comparison to determine equality of values". When the cache compares the value? for what?
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Are weakKeys() and weakValues() equivalent? (one of them was collected, the entry is expired)

No, if a key or value is collected, the Entry itself will not expire. You will still have access to the Entry, but the "reference" to the key and value will point you to null.

Guava doc said: "when this method is used, the resulting cache will use identity (==) comparison to determine equality of values". When the cache compares the value? for what?

In Java, Object variables are basically pointers, which means they store an 8-bit address in the memory block containing the object. So, the documentation says that it will not compare objects (because they are null), but references to objects.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!