I can create 2 object if I call the getInstance method after calling the reflection method. Frist in constructor in checks for object value is null, if fails and create a new object. Again new object is created when calling getInstance method. Browser instance2; Constructor constructor = Browser.class.getDeclaredConstructor(); constructor.setAccessible(true); instance2=constructor.newInstance(); Browser instance1= Browser.getInstance(); System.out.println("instance 1 : "+instance1.hashCode()); System.out.println("instance 2 : "+instance2.hashCode()); I see different has code for the above code. How to restrict this?
Great explanation 💙 crisp and clear
Thank you so much Naveen🙏
Very Nice 👍
Plz continue this series of covering important design patterns
Quite an informative one and really look forward to more such videos in implementing various such design patterns in test automation frameworks !!
I can create 2 object if I call the getInstance method after calling the reflection method. Frist in constructor in checks for object value is null, if fails and create a new object. Again new object is created when calling getInstance method.
Browser instance2;
Constructor constructor = Browser.class.getDeclaredConstructor();
constructor.setAccessible(true);
instance2=constructor.newInstance();
Browser instance1= Browser.getInstance();
System.out.println("instance 1 : "+instance1.hashCode());
System.out.println("instance 2 : "+instance2.hashCode());
I see different has code for the above code.
How to restrict this?
Hi bro, did you got solution for this