为什么getPlatformId()
不可见的SalesforcePlatform
在子类中的方法getPlatformName()
?代码块不完整。 SalesforcePlatform
是Platform
的子女。它是在不同的包比Platform
,但这不应该阻止其访问平台的保护方法,对吗?的Java为什么这种方法不可见
很抱歉,如果我错过了一些明显。
package com.dragon.dictionary;
public class Platform extends RepositoryObject
implements IPlatform{
protected final Long id ;
protected final String name;
protected static final String platformDbTbl = DragonConstants.TABLE_PREFIX + "platform";
protected Platform(Long platformId, String platformName){
id = platformId;
name = platformName;
};
protected Platform(String platformName){
Platform platform = Platform.getPlatformByName(platformName);
id = platform.getPlatformId();
name = platformName;
};
protected Long getPlatformId(){
return this.id;
};
protected String getPlatformName(){
return this.name;
}
....
}
package com.dragon.dictionary.salesforce;
import com.dragon.dictionary.Platform;
public class SalesforcePlatform extends Platform{
// prevent instantiation
private SalesforcePlatform() {
super("salesforce");
}
private SalesforcePlatform(Long platformId, String platformName) {
super(platformId, platformName);
}
public static SalesforcePlatform getPlatformByName(String platformName){
Platform platform = Platform.getPlatformByName(platformName);
SalesforcePlatform salesforcePlatform = new SalesforcePlatform(platform.getPlatformId(), platform.getPlatformName());
return salesforcePlatform;
}
}
编辑:
谢谢!因此,基于响应,你说,这将在子类中工作过:
private SalesforcePlatform(Platform platform) {
this.id = platform.getPlatformId();
this.name = platform.getPlatformName();
}
似是而非。但是,OP没有向我们显示调用代码,所以我们不能完全确定这一点。 – 2014-09-25 22:07:59
@StephenC他向我们展示了'SalesforcePlatform salesforcePlatform =新SalesforcePlatform(platform.getPlatformId(),platform.getPlatformName());'在静态情况下,这是getPlatformId'的'唯一的发生。所以我认为这是问题 – Robin 2014-09-25 22:18:34
谢谢@Robin我最终将保护的方法更改为public - – 2014-09-25 22:39:25