Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTomasz Halaczkiewicz
21,845 Pointsnew MapLocation(0, 2, map)
new MapLocation(0, 2, map) What does "map" at the end of that line stand for? How does it work ? Please help Im confused
2 Answers
Steven Parker
231,198 PointsThe map variable contains a newly-created map object.
In the code above the line you quoted, there's another line with this:
Map map = new Map(8, 5);
So that map object is being passed as one of the arguments to the constructor of MapLocation. That constructor uses the provided map to confirm that the location coordinates are within the map boundaries. Since the location is (0,2)
and the map is 8x5
, it should be fine.
Tomasz Halaczkiewicz
21,845 PointsWell I must have missed that somehow. Now it makes sense. Cheers Steven!
Tomasz Halaczkiewicz
21,845 PointsTomasz Halaczkiewicz
21,845 PointsThanks for your answer Steven! I'm still confused though. Since MapLocation constructor takes 2 int arguments shoudn't we pass just that ?
It would make sense if we passed x, y and Point object but having "map" as third argument?
Steven Parker
231,198 PointsSteven Parker
231,198 PointsThis program evolves as the course progresses, the original definition for MapLocation that you show here takes only 2 arguments, but later in the course it is expanded to take a Map as a third argument which is used to validate the other 2.
The calls in this video are using that new format. Perhaps you skipped an earlier video, or part of one, where that change was made?