[rules-users] Getter/Setter Methods for declared types
Wolfgang Laun
wolfgang.laun at gmail.com
Fri Jun 28 04:07:23 EDT 2013
You may have overlooked that
*e.setBar = 2;*
is NOT equivalent to
*mark.setName("Mark");*
Just Java, you know ;-)
-W
On 28/06/2013, droolster <quant.coder at gmail.com> wrote:
> Hello,
>
> At compile time, are the getter and setter methods automatically created
> for
> a declared type. In the Drools Expert PDF it gives the following example:
>
> declare Person
> name : String
> dateOfBirth : java.util.Date
> address : Address
> end
>
> and it states that the following class is generated:
>
> public class Person implements Serializable {
> private String name;
> private java.util.Date dateOfBirth;
> private Address address;
> // empty constructor
>
> public Person() {...}
> // constructor with all fields
>
> public Person( String name, Date dateOfBirth, Address address ) {...}
> // if keys are defined, constructor with keys
>
> public Person( ...keys... ) {...}
>
> *// getters and setters*
> // equals/hashCode
> // toString
> }
>
> Then the setter is referenced as follows:
>
> rule "Using a declared Type"
> when
> $p : Person( name == "Bob" )
> then
>
> // Insert Mark, who is Bob's mate.
>
> Person mark = new Person();
> *mark.setName("Mark");*
> insert( mark );
> end
>
> ----
>
> I tried the same with this simple declared type:
>
> declare Foo
> bar : int
> end
>
> rule "abc"
> when
> some condition
> then
> Foo e = new Foo();
> * e.setBar = 2;*
> insert (e);
> end
>
> But the compiler complains indicating that it "cannot be resolved or is not
> a field".
>
> Do I need to specify the getter/setters in my DRL file explicitly?
>
> Thank you for your help in advance.
>
> Regards
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Getter-Setter-Methods-for-declared-types-tp4024609.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list