Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

this keyword in android

Why do we use the this keyword along with the method name in Android to call a method from another method within the same class. In Java or C# we can call other method directly without the this keyword, as in the code below.

public final String getElementValue( Node elem )
 {
     Node child;
     if( elem != null)
     {
         if (elem.hasChildNodes())
         {
             for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() )
             {
                 if( child.getNodeType() == Node.TEXT_NODE  )
                 {
                     return child.getNodeValue();
                 }
             }
         }
     }
     return "";
 }

 /**
  * Getting node value
  * @param Element node
  * @param key string
  * */
 public String getValue(Element item, String str)
 {      
     NodeList n = item.getElementsByTagName(str);       
     return this.getElementValue(n.item(0));
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't have to use the this keyword in this case, it is done implicitly anyway. Sometimes it's clearer, and sometimes it makes Eclipse auto-complete the method name :P


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...