D
D
DDwrt1002019-08-26 17:05:48
Java
DDwrt100, 2019-08-26 17:05:48

Inheritance in Java, how to properly inherit a method?

Good afternoon.
There is an initial class which contains some methods.
Something like:

public List<datastrucutre> calculate(Math math){
//somecode
return List<datastrucure>;
}

I want to create a derived class that has the same methods but is considered a little different.
I create a class and say with the help of extend from whom I inherit
And write the following code.
@Override
public List<datastrucutreEXTENDSMATH> calculate(Math math){
//somecode, changed
return List<datastrucureEXTENDMATH>;

however, the compiler throws an error
Error:(34, 40) java: giveBy() in cannot override giveBy(r) in
return type java.util.List is not compatible with java.util.List<>
Error:(33, 5) java : method does not override or implement a method from a supertype
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2019-08-26
@DDwrt100

The inherited and the successor must have the same prototype, i.e. the same name, input parameters, and return data type.
You have different types returned.
Way out in the forehead - to return the base type, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question