×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Mar 2010
    Posts
    136

    What is this here?

    I understand that this keyword can be used inside any method to refer to the current object.
    But I don’t know how to explain other people if we write like that in the program.

    public class TFileReadWriteMIDlet extends MIDlet {
    static TFileReadWriteMIDlet tfilereadwritemidlet;
    Display display;

    public TFileReadWriteMIDlet() {
    TFileReadWriteMIDlet .tfilereadwritemidlet=this;
    }

    protected void startApp() throws MIDletStateChangeException {

    display=Display.getDisplay(this);

    Please teach me how to explain that two lines.
    This here means a MIDlet?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: What is this here?

    It is exactly as you say. "this" refers to the object that is executing the method.

    Graham.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: What is this here?

    Quote Originally Posted by komomo View Post
    I understand that this keyword can be used inside any method to refer to the current object.
    But I don’t know how to explain other people if we write like that in the program.

    public class TFileReadWriteMIDlet extends MIDlet {
    static TFileReadWriteMIDlet tfilereadwritemidlet;
    Display display;

    public TFileReadWriteMIDlet() {
    TFileReadWriteMIDlet .tfilereadwritemidlet=this;
    }

    protected void startApp() throws MIDletStateChangeException {

    display=Display.getDisplay(this);

    Please teach me how to explain that two lines.
    This here means a MIDlet?
    In TFileReadWriteMIDlet .tfilereadwritemidlet=this; // here you are assigning the current instance of the Midlet to the static variable tfilereadwritemidlet

    display=Display.getDisplay(this); // here you are passing the current instance of the Midlet to get a reference to its display, on which you can set any displayable (like form or Canvas) later
    Thanks,
    Ekta

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×