Work with recursion and universal interfaces

I have three common interfaces (with feedback between the two of them) and you want to process them in a recursive way:

public interface User<R extends Role<R,U>, U extends User<R,U>>
{
  public R getRole();
  public void setRole(R role);
}

public interface Role<R extends Role<R,U>,U extends User<R,U>>
{
  public List<R> getRoles();
  public void setRoles(List<R> roles);

  public List<U> getUser() ;
  public void setUser(List<U> user);
}

Now I want to do some processing with recursion in the class Worker:

public <R extends Role<R,U>,U extends User<R,U>> void recursion(List<R> roles)
{
  for(R role : roles)
  {
    recursion(role.getRoles());
  }
}

I am getting this error and I did not understand why this is not working or how I can solve it:

Bound mismatch: The generic method recursion(List<R>) of type Worker is not
applicable for the arguments (List<R>). The inferred type User<R,User<R,U>>
is not a valid substitute for the bounded parameter <U extends User<R,U>>
+5
source share
2 answers

I changed it without using common wildcards ?, so it compiles.
After removing the non-issue declaration methods:

public interface Role<R extends Role<R, U>, U extends User<R, U>> {
    public List<Role<R, U>> getRoles(); // Change here to return type
}

public interface User<R extends Role<R, U>, U extends User<R, U>> { // No change
}

// Change to method parameter type
public static <R extends Role<R, U>, U extends User<R, U>> void recursion(List<Role<R, U>> roles) {
    for (Role<R, U> role : roles) { // Change to element type
        recursion(role.getRoles());
    }
}

, - - , , .

! !

+2

, U . U, ? :

public <R extends Role<R,?>> void recursion(List<R> roles)
{
  for(R role : roles)
  {
    recursion(role.getRoles());
  }
}
+2

All Articles