0

I have an interface in java, called Action and has no functions

I also have an interface in java called State which has this function

public Set<Action> getPossibleActions();

I have this enum

public enum Movement implements Action{...}

and this class

public class Tiles implements search.State{

which implements the function

    public Set<Movement> getPossibleActions() {...}
        Set<Movement> movements = new LinkedHashSet<Movement>();
...
        }
        return movements;
    }

Why my last function does not work? I get the message that the return type is incompatible with the function public Set getPossibleActions();

As I set my class Movement to implement interface Action, my Movement isn't an Action? Therefore it should work... What I am doing wrong?

How do I solve that?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Jim Blum
  • 2,656
  • 5
  • 28
  • 37
  • 3
    `Movement` is an `Action`, but a `Set` is not a `Set.` – Sotirios Delimanolis Feb 04 '14 at 15:42
  • 2
    Use `Set extends Action>` instead – Sebastian Feb 04 '14 at 15:43
  • @SotiriosDelimanolis Thanks a lot Sotiri :) And how I fix that? I can't find any way... – Jim Blum Feb 04 '14 at 15:44
  • @Sebastian Thanks. If I used it correctly, this did not work for me – Jim Blum Feb 04 '14 at 15:50
  • @Sebastian where I should add that? Because It seems that at the other question the answerers are responding by the same thing, but I cannot find where to put that? Should I do it to define the return type next to getPossibleActions()? or should I cast the movement I return. I tried both, but it does not work for me... – Jim Blum Feb 04 '14 at 16:00
  • If you are adding to it use `Set super Action>` and if you are retrieving from it use `Set extends Action>` but if you need to do both you need to specify a specific type. – Prince Feb 04 '14 at 16:02
  • Thanks a lot @Prince But I still cant find out, how this could be used at my last function... As a return type, or a the type of the movements variable? – Jim Blum Feb 04 '14 at 16:10
  • Either change the `interface` method to `public Set extends Action> getPossibleActions()` or change the implementation method to use `Set`. In the latter case you can still add instances of `Movement` to a `Set`. – Holger Feb 04 '14 at 16:28

0 Answers0