Results 1 to 12 of 12
  1. #1
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default 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);

    }

    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default 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:

    Java Code:
    public class FIFOCache<K, V> extends CacheAlgorithm<K, V> { ... }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default 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:
    Java Code:
    public class FIFOCache<K, V> extends CacheAlgorithm<K, V>
    as well?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default 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".

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default 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.

    ** This space for rent **

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o

    Quote Originally Posted by Tolls View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o

    Quote Originally Posted by DarrylBurke View Post
    How sad that nobody responded in this thread.
    Do I hear something?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default 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.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o

    Quote Originally Posted by gamerongvangtp View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: name clash: get(K)..and get(K)..have the same erasure,yet neither overrides the o

    Oh, OK. Thank you very much.

Similar Threads

  1. Replies: 81
    Last Post: 12-23-2011, 11:01 AM
  2. clash of types
    By t638403 in forum New To Java
    Replies: 0
    Last Post: 11-03-2011, 02:19 PM
  3. invoking parent method even though child overrides it...
    By vinod_javaranch in forum New To Java
    Replies: 2
    Last Post: 08-18-2011, 05:33 PM
  4. Type Erasure
    By Lil_Aziz1 in forum New To Java
    Replies: 3
    Last Post: 06-29-2010, 09:57 AM
  5. Replies: 0
    Last Post: 01-26-2008, 12:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •