1

下面是我的类的结构:

public class Address {
                private String street;
        private int phone;
        public void setStreet(String s){street = s;}
        public void setPhone(int p){phone = p;}
        public String getStreet(String s){return street;}
        public int getPhone(){  return phone;   }
}
public class Borrower {
    Address adr = new Address();
    public void setAddress(String s, int p) {
        adr.setStreet(s);
        adr.setPhone(p);
    }   
    public Address getAddress() {   return adr; }   
}

我正在使用的 Drools 表达式:-

rule "Nested Address"
    salience -10    
    when
        $bo : Borrower(Address.street.equals("USA") && Address.phone != 717)
        $loanApp : LoanApplication()        
    then 
        $loanApp.addFeedbackMessage(FeedbackMessages.LOCATION_NOT_US);  
        System.out.println("Nested Address  " + $bo.adr.street + ", Nested Phone " + $bo.adr.phone);
end

上面给了我错误:

Unable to Analyse Expression Address.street.equals("USA"):

有人可以告诉我我做错了什么吗?

4

2 回答 2

4

您应该使用属性名称“地址”(注意小写 a)而不是类地址。所以:

rule "Nested Address"
    salience -10    
    when
        $bo : Borrower(address.street.equals("USA") && address.phone != 717)
        $loanApp : LoanApplication()        
    then 
        $loanApp.addFeedbackMessage(FeedbackMessages.LOCATION_NOT_US);  
        System.out.println("Nested Address  " + $bo.adr.street + ", Nested Phone " + $bo.adr.phone);
end
于 2013-10-13T17:07:57.873 回答
2

您应该使用“adr”(属性名)而不是“地址”(类名):

rule "Nested Address"
    salience -10    
    when
        $bo : Borrower(adr.street.equals("USA") && adr.phone != 717)
        $loanApp : LoanApplication()        
    then 
        $loanApp.addFeedbackMessage(FeedbackMessages.LOCATION_NOT_US);  
        System.out.println("Nested Address  " + $bo.adr.street + ", Nested Phone " + $bo.adr.phone);
end
于 2015-08-12T09:08:16.217 回答