Why I got incompatible types?

144 views Asked by At
private Pacman pacman;

public Location whereIsGhost(){
return pacman.getLocation();
}

incompatible types: java.awt.Point cannot be converted to ch.aplu.jgamegrid.Location

How to fix it? Which type a compatible with java.awt.Point?

3

There are 3 answers

0
Elliott Frisch On BEST ANSWER

I believe you have three choices

  1. Modify Pacmage getLocation to return a ch.aplu.jgamegrid.Location, or
  2. Modify whereIsGhost to return a java.awt.Point, or
  3. Modify Location to extend Point.

As for which types are compatible with java.awt.Point the Javadoc lists no known sub-classes.

0
splrs On

You should return a Point object or your Location object should extend Point.

0
Stav Saad On

Point does not extends Location, therefore it cannot be cast to one.

Simply create a new Location based on the parameters of the Point.

Both types has no relation to each other.