name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the other
name clash: get(K) in CachingSolution.FIFOCache and get(K) in CachingSolution.CacheAlgorithm have the same erasure, yet neither overrides the other
I can't override method get(K) in the FIFOCache.
Here is the class:
package CachingSolution;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
public class CacheAlgorithm<K, V> {
protected static final float hashTableLoadFactor = 0.75f;
protected LinkedHashMap<K, V> map;
protected int cacheSize;
public CacheAlgorithm(int cacheSize) {
this.cacheSize = cacheSize;
int hashTableCapacity = (int) Math.ceil(cacheSize / hashTableLoadFactor) + 1;
map = new LinkedHashMap<K, V>(hashTableCapacity, hashTableLoadFactor, false) {
// (an anonymous inner class)
private static final long serialVersionUID = 1;
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > CacheAlgorithm.this.cacheSize;
}
};
}
public synchronized V get(K key) {
return map.get(key);
}
public synchronized void put(K key,V value) {
map.put(key, value);
}
public synchronized void clear() {
map.clear();
}
public synchronized int usedEntries() {
return map.size();
}
public synchronized Collection<Map.Entry<K, V>> getAll() {
return new ArrayList<Map.Entry<K, V>>(map.entrySet());
}
public synchronized Collection<V> values() {
return (Collection<V>) map.values();
}
public synchronized boolean containKey(K _key) {
return map.containsKey(_key);
}
}
-----------------
package CachingSolution;
public class FIFOCache<K, V> extends CacheAlgorithm{
public FIFOCache(int cacheSize){
super(cacheSize);
}
//@Override
public synchronized V get(K key) {
return map.get(key);
}
}
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
You're extending from the raw class; make that:
Code:
public class FIFOCache<K, V> extends CacheAlgorithm<K, V> { ... }
kind regards,
Jos
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
You can't declare a method with the same signature in a child class as one in the parent without overriding the parent.
Presumably that child class should read:
Code:
public class FIFOCache<K, V> extends CacheAlgorithm<K, V>
as well?
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
I used an annotation @Override but it still have error , "method does not override or implement a method from a supertype".
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
You did read the two previous replies did you?
kiind regards,
Jos
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
I think we're invisible again.
I really must find a way to use my amazing powers for good!
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
Quote:
Originally Posted by
Tolls
I think we're invisible again.
I really must find a way to use my amazing powers for good!
Mwah, being invisible has its advantages too; you'll get used to it ;-)
kind regards,
Jos
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
How sad that nobody responded in this thread.
db
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
Quote:
Originally Posted by
DarrylBurke
How sad that nobody responded in this thread.
Do I hear something?
kind regards,
Jos
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
I read. But I don't know hoa to repair it.
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
Quote:
Originally Posted by
gamerongvangtp
I read. But I don't know hoa to repair it.
Ahem, read reply #2 and #3 again. Tolls and I were both spoonfeeding you.
kind regards,
Jos
Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o
Oh, OK. Thank you very much.