1

We need to close a connection when an object is evicted (timed out) of a cache. In trying to create a CacheEventListener for ehcache (version 2.10.4) we get:

The inherited method Object.clone() cannot hide the public abstract method in CacheEventListener

Is there a way around this? How can this work?! Is there an alternative?

markthegrea
  • 3,731
  • 7
  • 55
  • 78
  • How did you get that error? What were you trying to do? – Kayaman May 15 '18 at 13:42
  • If you make a class that implements CacheEventListener, you get the above error. The "web" says you can't get around it. – markthegrea May 15 '18 at 13:43
  • What about extending `CacheEventListenerAdapter`? Ah, seems to be a compiler issue. So haven't they fixed that at EhCache? It's their fault after all (or at least they're the only one who might do anything about it). Hmm, let me try something. – Kayaman May 15 '18 at 13:46
  • I think I got it. I overrode "clone" in my class. Seems to work but it is a very odd bug. – markthegrea May 15 '18 at 13:50
  • Related https://stackoverflow.com/questions/6837362/the-inherited-method-object-clone-cannot-hide-the-public-abstract-method – Kayaman May 15 '18 at 13:52
  • Yea, saw that. It is just about the only thing on the web about this problem. We almost switched to Caffeine because of this. – markthegrea May 15 '18 at 13:53

1 Answers1

1

So the issue is that Object.clone() is protected, and therefore any interface declaring a public clone() would not accept Object.clone() as an implementation.

As I imagined, either implementing a public clone() yourself or extending the adapter (which implements all of course) would solve that problem.

The related posting The inherited method Object.clone() cannot hide the public abstract method seems to go deeper and is unsolvable, but since there's no intersection types here, this is just a tiny annoyance.

It's really true what they say about clone(), don't do it.

Kayaman
  • 72,141
  • 5
  • 83
  • 121