A class error override method that extends a common class

i has class A that extends class B, and class B extends general class

my class A:

public class MyCustomerReviewConverter<SOURCE extends CustomerReviewModel, TARGET extends ReviewData> extends CustomerReviewConverter{

    @Override
    public void populate(final SOURCE source, final TARGET target) {.....}

extended class B is

public class CustomerReviewConverter extends AbstractPopulatingConverter<CustomerReviewModel, ReviewData>{

    @Override
    public void populate(final CustomerReviewModel source, final ReviewData target)
    {..........}

but i get an error

 Name clash: The method populate(SOURCE, TARGET) of type MyCustomerReviewConverter<SOURCE,TARGET> has the same erasure as populate(CustomerReviewModel, ReviewData) of type 
     CustomerReviewConverter but does not override it

what's wrong?

As the second parameter in the fill method, I have to pass the class

MyReviewData extends ReviewData{...}

early

Andrea

+4
source share
3 answers

Hard and hard to explain.

  • Type parameters are defined in general AbstractPopulatingConverter.
  • Type parameters are instantiated in CustomerReviewConverter.
  • Then you try again to create the parameters of the instantiated type in MyCustomerReviewConverter.

. , ( ).

:

@Override
public void populate(final CustomerReviewModel source,
        final ReviewData target) { /* ... */ }

:

public void populate(final MyCustomerReviewModel source,
        final MyReviewData target) { /* ... */ }

populate() MyCustomerReviewConverter MyCustomerReviewModel MyReviewData, populate, .

+2

<SOURCE, TARGET> B <CustomerReviewModel, ReviewData>. B, A :

public class MyCustomerReviewConverter extends CustomerReviewConverter {
    @Override
    public void populate(final CustomerReviewModel source, final ReviewData target) 
        { ... }
}

AbstractPopulatingConverter , , B, .

@Robby , , .

+1

You should expand CustomerReviewConverter<SOURCE, TARGET>(perhaps you did not add its definition to the question) instead of the raw type. Then you need to override public void populate(SOURCE source, TARGET target).

0
source

Source: https://habr.com/ru/post/1584860/


All Articles