Unlike value, you can't rename this special field variable. This special field variable field inside the set method is an alias for the backing field of the property-a backing field is just a field that is used by properties when you want to modify or use that field data. ![]() If empty, stop execution and throw an exception otherwise, reassign the value to a special field variable. We validated the value by checking if the value is empty. The parameter value passed to the set method represents the actual value that was assigned to the property by users-you can change the parameter name if you wish, but value is much preferred. ![]() You can see we defined our own setter method set(value) for the title right below the property definition-note that you can't modify this set() method signature because this is what the compiler expects as a custom property setter function. Throw IllegalArgumentException ( "Title must not be empty" )
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |