Home > DeveloperSection > Forums > How to solve Java generics name clash , has the same erasure?
john rob

Total Post:108

Points:756
Posted on    October-16-2014 12:59 AM

 Java OOPS  Java 
Ratings:


 1 Reply(s)
 852  View(s)
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.



Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    October-16-2014 1:08 AM

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

}


Don't want to miss updates? Please click the below button!

Follow MindStick