Results 1 to 4 of 4
Thread: instanceof question
- 02-16-2013, 11:49 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
instanceof question
I am trying to check if the cell contains an object of type Anteater using instanceof. However, when i tried to compile it I get an error message stating
Am I going about this all wrong? Thank you for any advice you can render.WorldOfAntsSim.java:391: illegal start of expression
if ((y>0) && (world.getAt(x, y-1) != instanceof Anteater))
^
WorldOfAntsSim.java:393: illegal start of expression
if (world.getAt(x, y-1) == instanceof Ant)
^
Java Code:public void move() // Must define this since virtual { // Pick random direction to move int dir = (int) (Math.random() * 4); // Try to move up, if not at an edge and empty spot if (dir==0) { if ((y>0) && (world.getAt(x, y-1) != instanceof Anteater)) { if (world.getAt(x, y-1) == instanceof Ant) { world.setAt(x,y-1,world.getAt(x,y)); // Move to new spot world.setAt(x,y,null); y--; breedTicks++; } else { world.setAt(x,y-1,world.getAt(x,y)); // Move to new spot world.setAt(x,y,null); y--; breedTicks++; untilStarve--; } }
- 02-16-2013, 11:54 PM #2
Senior Member
- Join Date
- Oct 2010
- Posts
- 317
- Rep Power
- 3
Re: instanceof question
Hi tngo,
Try this:
Regards.Java Code:if ((y>0) && !(world.getAt(x, y-1) instanceof Anteater))
- 02-17-2013, 04:39 AM #3
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
- 02-18-2013, 12:23 AM #4
Senior Member
- Join Date
- Oct 2010
- Posts
- 317
- Rep Power
- 3
Similar Threads
-
Instanceof
By KevinNguyen in forum New To JavaReplies: 12Last Post: 11-08-2012, 05:55 PM -
instanceof
By AedonetLIRA in forum New To JavaReplies: 3Last Post: 12-01-2010, 12:34 AM -
Class, SubClass type (InstanceOf) Question
By indyjoel in forum New To JavaReplies: 6Last Post: 11-07-2010, 03:55 AM -
Use of keyword instanceof
By darek9576 in forum New To JavaReplies: 3Last Post: 03-14-2010, 10:35 PM -
super instanceof Class?
By mikeiz404 in forum New To JavaReplies: 11Last Post: 01-23-2009, 07:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks