計劃從一個超類擴展多個類,爲了簡單起見,我試圖在超類中聲明公共變量,所以我只需要爲它們分配一個值在子類中,但是子類不能識別變量。在子類實現中找不到的變量中聲明的變量
抽象類:
public abstract class AbstractAPIService {
public String APIDocumentation; //Selected API Documentation location
}
實現示例:
@Path("/Transport")
@Stateless
public class TransportAPI extends AbstractAPIService {
APIDocumentation = "http://docs.transportapi.com/index.html?raml=http://transportapi.com/v3/raml/transportapi.raml";
//Desired Functionality:
...
}
據我所看到的,它看起來法律和它看起來像它應該工作,但Netbeans的只是不承認變量。
或者將字符串作爲參數傳遞給超級用戶,它具有在超類ctor中可用的優點(在構造函數中調用可覆蓋的方法時非常不恰當)。 –
這迫使你擁有該構造函數。可能的,但不是(我的)首選解決方案。 – GhostCat