1
public class MyMap extends LinkedHashMap<String, Serializable>
{
    @Override
    public Serializable get(String key)
    {
        return null;
    }
}

error: method does not override or implement a method from a supertype

Ufx
  • 2,595
  • 12
  • 44
  • 83

3 Answers3

3

Remove the @Override annotation. That will fix the error.

Keep in mind that if you actually want to override some parent method, this is not what you want to do. Instead, look for possible typos, error or type mismatch in your get method.

In your case, you probably want:

@Override
public Object get(Object key)
{
    return null;
}
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
3

The signature of get is public V get(Object key)

So you need to change the parameter type to Object instead of String.

Tudor
  • 61,523
  • 12
  • 102
  • 142
3

The method you're trying to override has the following signature:

public Serializable get(Object key);

To override it, your method's argument therefore has to be of type Object, not String:

public class MyMap extends LinkedHashMap<String, Serializable>
{
    @Override
    public Serializable get(Object key)
    {
        return null;
    }
}
NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • Why public V get(Object key) successfully overrides by @Override public Serializable put(String key, Serializable value) { } ? – Ufx Dec 11 '11 at 17:08
  • @user1034253: I am sorry but I don't understand the question. – NPE Dec 11 '11 at 17:09
  • public Serializable put(String key, Serializable value) - compiled, public Serializable get(String key) as you say is need replace String by Object – Ufx Dec 11 '11 at 17:11
  • @aix - OP's asking why `put` doesn't follow the same pattern. There's a popular post about this somewhere, we should just link it. – Paul Bellora Dec 11 '11 at 17:12
  • @user1034253 - See this post: http://stackoverflow.com/questions/857420/what-are-the-reasons-why-map-getobject-key-is-not-fully-generic – Paul Bellora Dec 11 '11 at 17:13