Eren
Eren

Reputation: 1

How to call a method with different Generic type

I've got to implement these two methods using recursivity: - The first one is to return a value at a Node in the PositionList - The second one to convert a crypted List<Integer> into a (<Character>) List

in the decrypt method I´m trying to call the getPositon method but getting the Error "The method getPosition(PositionList<E>, Position<E>, int) in the type Recursion is not applicable for the arguments (PositionList<Character>, Position<Integer>, int)"

How can I call .decrypt giving it a PositonList<Character> and a Position<Integer>?

public static <E> Position<E> getPosition(PositionList<E> l, Position<E> pos, int n) {

     if(n < 0) {
         pos = l.prev(pos);
         return getPosition(l, pos, n+1);
     }
     if(n > 0) {
         pos = l.next(pos);
         return getPosition(l, pos, n-1);
     }
     else {
         return pos;
     }
  }

  public static PositionList<Character> decrypt(PositionList<Character> alphabet, PositionList<Integer> encodedText) {

      PositionList<Character> newList;
      Position<Integer> pos; 


      if(counter <= alphabet.size()) {
          if(counter == 0) {
              pos = encodedText.first();
              value = pos.element();
          }
          if(counter > 0) {
              pos = encodedText.next(pos);
              value = pos.element();
          }
          newList.addLast(getPosition(alphabet, pos, value));
          counter++;
          return decrypt(alphabet, encodedText);
      }

      else {
          counter = 0;
          return newList;
      }
  }

Upvotes: 0

Views: 54

Answers (1)

Cedric
Cedric

Reputation: 552

You can pass multiple generic types to methods like so:

public static <E, F> Position<F> getPosition(PositionList<E> l, Position<F> pos, int n) {
    ...
}

Upvotes: 1

Related Questions