Ansichten: QuotePaste - CodePaste - NoPaste
Codesnippet eingetragen am 18.1.2012 um 08:27
Von: Michael
Sprache: Java
Beschreibung: Shows what the Keyword this. does :) (and why you don't have to use it obsessively)
CodeSnippet:
  1.  
  2. public class foobar {
  3. public static void main(String[] args) {
  4. footwo bla = new footwo();
  5. bla.x = 1;
  6.  
  7. bla.giveittome(5);
  8. }
  9.  
  10. }
  11.  
  12.  
  13. class footwo {
  14. public int x;
  15.  
  16. public int giveittome(int x){
  17. System.out.println("This is this:"+this.x);
  18. System.out.println("And this is it without:"+x);
  19.  
  20. return x;
  21. }
  22. }
  23.  
  24. /******************************************
  25. * Result is:
  26. * This is this:1
  27. * And this is it without:5
  28. ******************************************/