2 Replies Latest reply on Oct 12, 2007 10:55 AM by Norman Richards

    non-void property setters

    Roger Goldman Newbie

      Is there any particular reason why the property setters are restricted to having a 'void' return type?

      It is sometimes convenient to have a class like:

      public class User {
       private String username;
       private String password;
       public String getUsername() { return this.username; }
       public User setUsername( String u ) { this.username = u; return this; }
       public String getPassword() { return this.password; }
       public User setPassword( String p ) { this.password = p; return this; }

      so that you can then do:
       User user = new User().setUsername("rag").setPassword("s3cr3t");

      Unfortunately, when we try to reference #{user.username}, we get
      value="#{user.username}": Property 'username' not writable on type java.lang.String.