活动对象库( active objects library,https://java.net/projects/activeobjects/pages/Home)出现了问题。
假设我有这样的ao实体:
@Implementation(PersonImpl.class)
interface Person extends Entity{
public String getName();
public String setName();
}
以及该实体的实现类:
class PersonImpl {
private Person person;
public PersonImpl(Person person){
this.person = person;
}
public String getName(){
if( isTodayIsMonday() )
return "I hate monday";
else
return person.getName();
}
}
问题在PersonImpl
类中。因为有了person.getName()
,我得到无限递归(总是调用impl类)。如何跳过调用实现(在PersonImpl
类中)并从数据库中获取名称?
发布于 2013-09-19 09:32:23
根据http://www.javalobby.org/articles/activeobjects/,通过检查调用堆栈,ActiveObjects自动避免了这个问题:
“我们可以用它来检查堆栈上一步上一步的定义实现。如果我们发现它启动了方法调用,我们将跳过定义的实现的重新调用,并实际执行方法调用。因此,从其定义的实现中对实体的任何调用都将跳过任何实现逻辑,从而避免递归。”
发布于 2013-09-19 08:29:28
private String getMyName(boolean isMonday) {
if (isMonday) {
return "I hate Monday";
}
return person.getName();
}
https://stackoverflow.com/questions/18888995
复制相似问题