BasePage.java的Java擴展類
public class BasePage {
//do stuff
}
Center.java
public class Center {
public BasePage click(){
click(button);
return new BasePage(this);
}
// do other stuff
}
public class Helper {
protected Center center;
// do stuff
}
Page.java
public class Page extends BasePage {
//do stuff
}
TestClass.java
public class TestClass extends Helper {
private Page page;
// I can use "center.click()" because TestClass extends from Helper,
// and "center" is a protected variable in Helper
// "center.click()" returns type 'BasePage'
// 'page' is a type 'Page' which extends 'BasePage'
// So why can't I put the result of "center.click()" into 'page' ?
page = center.click();
}
你的問題是什麼? –
你有什麼錯誤嗎? – kosa
您不能將超類引用分配給子類引用。 –