HOW TO SOLVE JAVA GENERICS NAME CLASH , HAS THE SAME ERASURE?

john rob

Total Post:108

Points:756
Posted by  john rob
OOPS  Java 
 1470  View(s)
Ratings:
Rate this:
I have superclass Foo. And a class Bar extending it.

public class Bar extends Foo

Function in Foo:

protected void saveAll(Collection<?> many)

Function in Bar:

public void saveAll(Collection<MyClass> stuff)

{

    super.saveAll(stuff);

}

Getting error :

Name clash: The method saveAll(Collection<MyClass>) of type Bar has the same erasure as saveAll(Collection<?>) of type Foo but does not override it.

  1. Jeet Verma

    Post:110

    Points:776
    Re: How to solve Java generics name clash , has the same erasure?

    You are overriding the saveAll method with an incompatible type. Perhaps you want to do something like:


    public class Bar extends Foo<MyClass>

    Function in Foo<E>

    protected void saveAll(Collection<E> many)

    and function in Bar:

    public void saveAll(Collection<MyClass> stuff)

    {

       super.saveAll(stuff);

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!