Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 此关键字用作引用变量_Java_This - Fatal编程技术网

Java 此关键字用作引用变量

Java 此关键字用作引用变量,java,this,Java,This,这是一个保存当前对象的引用ID的变量。 那么为什么它不能用作参考变量呢 Temp t = new Temp(); //Temp be any class t.show(); //show() be any method in Temp this.show(); // error 如果您所在的类没有show()方法,或者您试图从静态上下文中执行此操作,则只会引发错误 此保留当前对象的引用ID,因此它取决于您所在的位置,而不是刚刚创建的对象。仅当您所在的类没有

这是一个保存当前对象的引用ID的变量。 那么为什么它不能用作参考变量呢

Temp t = new Temp();  //Temp be any class
t.show();            //show() be any method in Temp
this.show();        // error

如果您所在的类没有
show()
方法,或者您试图从静态上下文中执行此操作,则只会引发错误


保留当前对象的引用ID,因此它取决于您所在的位置,而不是刚刚创建的对象。

仅当您所在的类没有
show()
方法或者您试图从静态上下文执行此操作时才会引发错误


保留当前对象的引用ID,因此它取决于您所在的位置,而不是刚刚创建的对象。

仅当您所在的类没有
show()
方法或者您试图从静态上下文执行此操作时才会引发错误


保留当前对象的引用ID,因此它取决于您所在的位置,而不是刚刚创建的对象。

仅当您所在的类没有
show()
方法或者您试图从静态上下文执行此操作时才会引发错误


保留当前对象的引用ID,因此它取决于您所在的位置,而不是刚刚创建的对象。

当前对象不是您上次引用的对象。下面是
这种用法的示例:

public class Temp {
    private int x = 3;

    public void show() {
        this.x = 4;
        this.show(); // same as show();
    }
}

当前对象不是您上次引用的对象。下面是
这种用法的示例:

public class Temp {
    private int x = 3;

    public void show() {
        this.x = 4;
        this.show(); // same as show();
    }
}

当前对象不是您上次引用的对象。下面是
这种用法的示例:

public class Temp {
    private int x = 3;

    public void show() {
        this.x = 4;
        this.show(); // same as show();
    }
}

当前对象不是您上次引用的对象。下面是
这种用法的示例:

public class Temp {
    private int x = 3;

    public void show() {
        this.x = 4;
        this.show(); // same as show();
    }
}
java中的“this”关键字用于引用代码运行的对象。 在比较对象本身时,它最有用。例如:

 public boolean equals(Object object) {
      return object == this;
 }
下面是帮助您理解的另一段代码:

 public class Test {

      public Test() {
      }

      public static void main(String... args) {
           Test test = new Test();//original test object
           Test test2 = new Test();
           test.equals(test);//returns true
           test.equals(test2);//returns false
      }

      public void equals(Test testParameter) {

           // in this particular case "this" refers to the 
           // original test object (defined in the main method)
           // as it is the only object calling this method.
           return testParameter == this; // "this" is the object that is calling the method
      }

 }
java中的“this”关键字用于引用代码运行的对象。 在比较对象本身时,它最有用。例如:

 public boolean equals(Object object) {
      return object == this;
 }
下面是帮助您理解的另一段代码:

 public class Test {

      public Test() {
      }

      public static void main(String... args) {
           Test test = new Test();//original test object
           Test test2 = new Test();
           test.equals(test);//returns true
           test.equals(test2);//returns false
      }

      public void equals(Test testParameter) {

           // in this particular case "this" refers to the 
           // original test object (defined in the main method)
           // as it is the only object calling this method.
           return testParameter == this; // "this" is the object that is calling the method
      }

 }
java中的“this”关键字用于引用代码运行的对象。 在比较对象本身时,它最有用。例如:

 public boolean equals(Object object) {
      return object == this;
 }
下面是帮助您理解的另一段代码:

 public class Test {

      public Test() {
      }

      public static void main(String... args) {
           Test test = new Test();//original test object
           Test test2 = new Test();
           test.equals(test);//returns true
           test.equals(test2);//returns false
      }

      public void equals(Test testParameter) {

           // in this particular case "this" refers to the 
           // original test object (defined in the main method)
           // as it is the only object calling this method.
           return testParameter == this; // "this" is the object that is calling the method
      }

 }
java中的“this”关键字用于引用代码运行的对象。 在比较对象本身时,它最有用。例如:

 public boolean equals(Object object) {
      return object == this;
 }
下面是帮助您理解的另一段代码:

 public class Test {

      public Test() {
      }

      public static void main(String... args) {
           Test test = new Test();//original test object
           Test test2 = new Test();
           test.equals(test);//returns true
           test.equals(test2);//returns false
      }

      public void equals(Test testParameter) {

           // in this particular case "this" refers to the 
           // original test object (defined in the main method)
           // as it is the only object calling this method.
           return testParameter == this; // "this" is the object that is calling the method
      }

 }

除非您不在
Temp
类中,或者您在
Temp
类中,但在静态上下文中,否则不会引发错误。除非您不在
Temp
类中,或者您在
Temp
类中,但在静态上下文中,否则不会引发错误。除非您不在
Temp
类中,或者您在静态上下文中,否则不会引发错误在
Temp
类中,但在静态上下文中。除非您不在
Temp
类中,或者您在
Temp
类中,但在静态上下文中,否则不会引发错误。那么“当前对象”是什么意思?@anmolsharma将其视为您所在的类。那么“当前对象”是什么意思呢意思是?@anmolsharma认为它是你所在的类。那么“当前对象”是什么意思?@anmolsharma认为它是你所在的类。那么“当前对象”是什么意思?@anmolsharma认为它是你所在的类。