Abstract General Class

I have the following class:

public abstract class Step {
    public abstract <S,T> S makeAStep(S currentResult, T element);
} 

and I'm trying to implement it, so it will take two ints and return their sum, something like this:

public class sumOfInts extends Step {
    public <Integer,Integer> Integer makeAStep(Integer currentResult, Integer element){
        return currentResult + element;
    }
}

but I get the following error:

Type sumOfInts must implement the inherited abstract method Step.makeAStep (S, T)

please help me (I need this for my homework in programming courses)

I ask you to very kindly write me a code that does what I want to execute, that will not have any errors or warnings, thanks in advance

+3
source share
2 answers
public abstract class Step<S,T> {
    public abstract S makeAStep(S currentResult, T element);
} 

public class SumOfInts extends Step<Integer,Integer> {
    // etc.
+11
source

I agree with Jonathan's answer.


, , .

, , . :

    public abstract class Step {
      public abstract <S,T> String makeAStep(S first, T second);
    }

    public class ConcatTwo extends Step {
      public <S, T> String makeAStep(S first, T second){
        return String.valueOf(first) + String.valueOf(second);
      }
    }

. , String.valueOf(Object), ( ). S T, -
S extend Integer .

+2

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


All Articles