Search code examples
javacompiler-errorsgreenfoot

Greenfoot incompatible type error


Made some simple game at work and used the fallowing code:

Player player = getOneIntersectingObject(player.class);

Which compiles and executes just fine, at work. Home, however, it won't compile it says that

incopatible types: Greenfoot.Actor cannot be converted to Player.

How is this posible? Player is a child of Actor. At work Greenfoot is 3.01 and at home 3.02, is that the problem? Thanks


Solution

  • There were changes to the generics in the Greenfoot API between 3.0.0, 3.0.1 and 3.0.2 so that is the reason why it is behaving differently at home to at work. In each case a cast will make sure it works on every version:

    Player player = (Player)getOneIntersectingObject(Player.class);