Hello!
This code is often found in the code (in any C-like language).
class One { One instanse; //Вот эта строчка не понятна ... //Здесь дальнейшая реализация } Such a line is always found in a singleton and (if I understood correctly) is called a global access point. The field of the class itself, in which the object of the class is enclosed, leads me to the idea of recursion, which is completely incomprehensible.
Questions:
- What does this field mean?
- What is this field used for?
- How is that even possible? After all, a class is the essence of a stamp, and an object is a cast from a stamp. It turns out the stamp contains a casting? Does each copy already contain a copy of itself?
- Optionally - where and in what book (website) is it clearly described?
static One instanse;- Igorprivate static One instance. - Andrew Kachalinpublic class SingleT { public int x, y; SingleT instance; SingleT(int x , int y){ this.x = x; this.y = y; } public static void main(String[] args) { SingleT st = new SingleT(5, 4); } }public class SingleT { public int x, y; SingleT instance; SingleT(int x , int y){ this.x = x; this.y = y; } public static void main(String[] args) { SingleT st = new SingleT(5, 4); } }public class SingleT { public int x, y; SingleT instance; SingleT(int x , int y){ this.x = x; this.y = y; } public static void main(String[] args) { SingleT st = new SingleT(5, 4); } }- Andrew Kachalinstatic), may be suitable, for example, to build aпрадед-дед-отец-сын-внук...chainпрадед-дед-отец-сын-внук...Those. each object contains a descendant of its own class. If withstatic- then it is 99% singleton. You can read about it yourself - rjhdby