Does setter method return type have to be void?

后端 未结 1 1421
青春惊慌失措
青春惊慌失措 2021-01-14 14:52

I change setter method return type to an object for ease eg: obj.setValue(newVal).setName(newName).setId(newId);

but after this change tomcat gives

相关标签:
1条回答
  • 2021-01-14 15:12

    Does jsf need setter for modifying the object even if it's modifier is public?

    Short answer : Yes.

    By convention, each field of a Bean should be private and be accessed/mutated by there respective getters and setters.

    Changing the field to public won't change anything, as when you type in the field name in your EL code, the server will search for the setFieldName(param) or getFieldName or isFieldName if your field is a boolean.

    Does setter method return type have to be void for jsf modifying an object value?

    Yes, the server will search void a signature containing void. Try it and see.

    0 讨论(0)
提交回复
热议问题