2 Replies Latest reply on Oct 12, 2007 10:55 AM by norman.richards

    non-void property setters

    roger_goldman2000

      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:

      @Name(user)
      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.

      Thoughts?