«это» ключевое слово в Java, чтобы ссылаться на объекте коды работают в Это в основном полезно вы сравниваете объект внутри себя.. Пример:
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», но в статическом контексте. – Codebender