For Programmers: Free Programming Magazines  


Home > Archive > Java Help > October 2004 > Re: simple IF question if (newplayer == goalkeeper) {throw









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: simple IF question if (newplayer == goalkeeper) {throw
Thomas Schodt

2004-10-28, 8:58 am

zcraven wrote:
> if (p2,p3,p4==Goalkeeper)
> {
> throw new IllegalArgumentException("You cannot put a goalkeeper
> in an outfield position");
> }
>
>
> I want to check that the variables p2 to p11 are of class OutfieldPlayer and
> not Goalkeeper (Both OutfieldPlayer and Goalkeeper are subtypes of abstract
> class Player). How do I write an if to check that the variables are of a
> certain class?


You should probably have a moveTo() method in Player
and override it as appropriate so
newplayer.moveTo(OUTFIELD)
would throw an exception if newplayer is an instance of Goalkeeper.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com