I ran the following script (java) and this gave me a weird result. Can anyone help explain?
import java.util.Objects; import org.apache.log4j.Logger; public class CacheTester { private static final Logger log = Logger.getLogger(CacheTester.class); @Test public void hashCodeTest() { for (int i = 0; i < 50; i++) {
The result of the log (they differ from each other):
---- Background ----
I wanted to use my own Generator key for @Cacheable annotation (Spring and ehCache).
public Object generate(Object target, Method method, Object... params) { int key = Objects.hashCode(method.getName(), params); log.info("key = " + key); return key; }
In this case, I believe that the cache is always skipped.
Then I have to change to this:
public Object generate(Object target, Method method, Object... params) { int result = method.getName().hashCode() : 0; result = 31 * result + Objects.hashCode(params); return result; }
thanks
source share