Such a question is how to correctly perform method 2 in method 1? With this picture (all methods are dynamic)

Какой-то другой класс { В нём какой-то метод() { К к = new K(); к.метод1(); } } class К { глобальная переменная = п; метод1 () {дёргает п; дергает метод2} метод2 () {дёргает(изменяет) п;} } 

Made a question from the comment in the topic: dynamic objects in Vaadin .

  • For the first time I hear about "dynamic methods". What do you mean by this term? - jmu 4:38 pm
  • most likely the fact that they are not static))). but in general yes, there is no such term in java - Viacheslav

1 answer 1

Well, there are at least two options (in fact the same thing):

1. Pass the object reference to method1 and call method2 using this link:

 class A{ void a(){ K k=new K(); k.meth1(k); } } class K{ void meth1(K k){k.meth2();} void meth2(){} } 

2. Use the this in the value of the reference to the object that called the method:

 class A{ void a(){ K k=new K(); k.meth1(); } } class K{ void meth1(){this.meth2();} void meth2(){} }