Results 1 to 12 of 12
- 05-28-2012, 10:35 AM #1
Member
- Join Date
- May 2012
- Posts
- 4
- Rep Power
- 0
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);
}
}
- 05-28-2012, 11:26 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
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:
kind regards,Java Code:public class FIFOCache<K, V> extends CacheAlgorithm<K, V> { ... }
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-28-2012, 11:28 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,458
- Rep Power
- 16
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:
as well?Java Code:public class FIFOCache<K, V> extends CacheAlgorithm<K, V>
Please do not ask for code as refusal often offends.
- 05-28-2012, 11:42 AM #4
Member
- Join Date
- May 2012
- Posts
- 4
- Rep Power
- 0
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".
- 05-28-2012, 11:52 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-28-2012, 12:23 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,458
- Rep Power
- 16
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!Please do not ask for code as refusal often offends.
- 05-28-2012, 12:26 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
- 05-28-2012, 01:58 PM #8
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-28-2012, 02:09 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
- 05-28-2012, 05:18 PM #10
Member
- Join Date
- May 2012
- Posts
- 4
- Rep Power
- 0
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.
- 05-28-2012, 05:48 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
- 05-28-2012, 06:14 PM #12
Member
- Join Date
- May 2012
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Generics & 'Type Erasure': disingenuous documentation?
By 2by4 in forum Advanced JavaReplies: 81Last Post: 12-23-2011, 10:01 AM -
clash of types
By t638403 in forum New To JavaReplies: 0Last Post: 11-03-2011, 01:19 PM -
invoking parent method even though child overrides it...
By vinod_javaranch in forum New To JavaReplies: 2Last Post: 08-18-2011, 04:33 PM -
Type Erasure
By Lil_Aziz1 in forum New To JavaReplies: 3Last Post: 06-29-2010, 08:57 AM -
name clash: equals(E) in and equals(java.lang.Object)
By AdRock in forum New To JavaReplies: 0Last Post: 01-25-2008, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks