• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Meaning of this line

 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Game.java is the previous Activity from where control move to PuzzleView.java

now,
this.game = (Game) context;

is in PuzzleView.java 's constructor
What is the meaning of tis line?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a Cast. See the bottom of this tutorial page for a description of what Casting is.
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep, here context is cast into Game..

still don't understand the meaning of this line..
what is the working of this line?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what that code does is assign the reference to the object stored by context variable to the variable named game (which is an instance variable). Presumably, the type of the game variable is not the Same as the type of the context variable. So the code uses an explicit cast to inform the compiler that the stored object is a Game and So can be assigned to the game variable.
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay,,
and here whose object context contains ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65340
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are we supposed to know that from one line of code?
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okey then..
can you please tell me the way , How to get myself know about whose object the context contains ??

P.S : Provide me an Example for the same, so that in future i could know myself and doesn't ask such a foolish questions again..

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shivam singhal wrote:okey then..
can you please tell me the way , How to get myself know about whose object the context contains ??


I don't know what you mean by "whose object," since there's no concept of object ownership in Java. In general though, to find out more about that variable, you'd have to look at the other code around that line, to see where the variable was assigned or passed in as a parameter. The name "context" should give you a clue though.

P.S : Provide me an Example for the same


No.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic