I have classes PageA and PageB.
Methods and variable are absolutely different.
But what is common for both of them, from PageA and PageB it should be possible to call methods of class Popup.
The problem is that after executing method "closePopup" of the class Popup, it should return instance of the class, which called him (PageA or PageB).
I have done following:
class PageA{
public PageA dosomethingA(){
//some code
return this;
}
public Popup openPopup(){
$("button.media").click();
return new Popup(PageA.class);
}
}
class PageB{
public PageB dosomethingB(){
//some code
return this;
}
public Popup openPopup(){
$("p.images").click();
return new Popup(PageB.class);
}
}
class Popup<T>{
private Class<T> callerClass;
public Popup(Class<T> callerClass) {
this.callerClass = callerClass;
}
public Popup doSomething1(){
//some code
return this;
}
public Popup doSomething2(){
//some code
return this;
}
public Popup doSomething3(){
//some code
return this;
}
public Class<T> closePopup(){
//some code
return callerClass;
}
}
Run:
pageA.dosomethingA()
.openPopup()
.doSomething1()
.closePopup()
//Error Object class is returned, PageA class should be returned
.dosomethingA();
pageB.dosomethingB()
.openPopup()
.doSomething2()
.doSomething3()
.closePopup()
//Error Object class is returned, PageB class should be returned
.dosomethingB();
The problem is that closePopup method returns an Object. How to fix it?