What is the point .....?



  • hiii [:)]

    what is the point from useing this statmenet in programming??

    i know how to use it ..... but i want to know the point from use it [:^)]



  • which statement?



  • Maybe the ... or ? operators?



  • Or maybe the 'this' keyword.



  • I think he means "it"



  • /* ThatObject: class for storing reference to MyObject /
    class ThatObject {
       MyObject myObject;
       ThatObject(MyObject mo) {
          myObject = mo;
       }
    }
    / MyObject: class for creating ThatObject and storing reference to it */
    class MyObject {
       ThatObject thatObject;
       MyObject() {
          thatObject = ThatObject(this);
       }
    }

    Or maybe this* is the point.

    * <FONT face="Courier New">.</FONT>



  • i mean (( <FONT color=#ff0000>this</FONT> )) keyword

    [*-)]



  • It's a handle for the object itself... (sorry if I'm not expressing that very well!)

    For example, say your coding a method for a class, and you need to know a certain property. Let's say your class is "engine" and your function needs to know the propery "oilPressure." Inside the method, you might code:

    <FONT face="Courier New">if(this.oilPressure < 20){</FONT>

    <FONT face="Courier New">   this.alert("Oil pressure is too low!");</FONT>

    <FONT face="Courier New">}</FONT>

    or something. It's psuedocode - so psue me.



  • @R.Flowers said:

    It's a handle for the object itself... (sorry if I'm not expressing that very well!)

    In a few programming languages it's a handle for the object itself. Not every language calls the current object "this".

    And ... uh... "soso123", maybe learning the language would be a pretty good idea.



  • ^

    ^

    ^

    [:$]

    sorry English is not my mother language

    because of that i have a problem in java [:(]

     



  • @soso123 said:

    ^

    ^

    ^

    [:$]

    sorry English is not my mother language

    because of that i have a problem in java [:(]

    English is not my mother tongue either (by a long shot, i'm french). But Sun's tutorials are not bad, and Bruce Eckel's Thinking in Java has been translated to a _lot_ of languages. And early versions (Thinking in Java versions 1, 2 and 3, version 4 being the latest release) are available for free online.



  • Not sure about Java, but C# also uses "this" to chain constructors:

    public class Foo
    {
        private bool _isSomeProperty;
       
        public Foo()
           : this(true)
        {}

        public Foo(bool isSomeProperty)
        {
           this._isSomeProperty = isSomeProperty;
        }
    }



  • @John Smallberries said:

    Not sure about Java, but C# also uses "this" to chain constructors:

    public class Foo
    {
        private bool _isSomeProperty;
       
        public Foo()
           : this(true)
        {}

        public Foo(bool isSomeProperty)
        {
           this._isSomeProperty = isSomeProperty;
        }
    }


    In Java, it's super



  • @ammoQ said:

    In Java, it's super

    yup, this certainly is super ;)



  • A couple of common uses for the "this" keyword are disambiguation and reference passing:

    <FONT face="Courier New">class Node {</FONT>

    <FONT face="Courier New">   private Node parent;</FONT>

    <FONT face="Courier New">   void setParent(Node parent) {</FONT>

    <FONT face="Courier New">      this.parent = parent;</FONT>

    <FONT face="Courier New">   }</FONT>

    <FONT face="Courier New">   void setChild(Node child) {</FONT>

    <FONT face="Courier New">      child.setParent(this);</FONT>

    <FONT face="Courier New">   }</FONT>

    <FONT face="Courier New">}</FONT>



  • @ammoQ said:

    @John Smallberries said:
    Not sure about Java, but C# also uses "this" to chain constructors:

    public class Foo
    {
        private bool _isSomeProperty;
       
        public Foo()
           : this(true)
        {}

        public Foo(bool isSomeProperty)
        {
           this._isSomeProperty = isSomeProperty;
        }
    }


    In Java, it's super

    Nope, it's also this.

    super allows you to call the overriden method of the superclass of your current class, the role of this is not to call the overriden constructor, but to call another version of the constructor (since constructors are magic functions you can't just call them the usual way).



  • @masklinn said:

    @ammoQ said:
    @John Smallberries said:
    Not sure about Java, but C# also uses "this" to chain constructors:

    public class Foo
    {
        private bool _isSomeProperty;
       
        public Foo()
           : this(true)
        {}

        public Foo(bool isSomeProperty)
        {
           this._isSomeProperty = isSomeProperty;
        }
    }


    In Java, it's super

    Nope, it's also this.

    super allows you to call the overriden method of the superclass of your current class, the role of this is not to call the overriden constructor, but to call another version of the constructor (since constructors are magic functions you can't just call them the usual way).



    Ah yes, of course you are right. Should have checked the C# example more carefully.


  • I love this.



  • <FONT face="Courier New">*this is confusing!</FONT>



  • @ammoQ said:


    In Java, it's super

    Yes, java is a sew-pah language (<-- monty python reference)



  • @Joost_ said:

    <font face="Courier New">*this is confusing!</font>


    Ah, the [i]other[/i] this.



  • Sorry, I couldn't control my Self.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.