Some methods are mutator methods, usually they do not return anything, the so-called setters. Others, such as the .plusDays () method of the LocalDate class, return a full instance of an object of type Localdate, so if you want to change the object, you need to point the existing object variable to the newly created one.
Is there a way to find out in advance whether the method will be a mutator or work as previously mentioned separately from finding its return value?
No, there is no way to find out (despite the documentation or implementation) whether the method will change some state.
, void, , - ( ?), - , ( , , , JVM).
void
, , , -, .
immutable, , , " , ?" , - . , ErrorProne @Immutable , .
@Immutable
, , void setProperty(PropertyType property), , (, -, , , ).
void setProperty(PropertyType property)
, Builders, (, Builder withProperty(PropertyType property)), , .
Builder withProperty(PropertyType property)
, , , ( ).
Source: https://habr.com/ru/post/1686097/More articles:R CMD error fails, devtools :: test () works fine - riOS11 how to synchronize a large rotation of a navigation bar by scrolling - swiftR CMD check / devtools :: test () and the current working directory is unit-testingHow to make a field depends on lst_price product product.product, but may be editable - fieldiOS 11 On-screen recording disabled VIDEO RECORDING - iphonePHP Can you update var inside a string? - variablesHow to create a linked server on a remote server with a local PC - sqlHow to insert an image into a space saving library? - androidHow to reduce image size in 1 MB - androidWhy are C static functions not going to the text section, but to the rhodate section? - cAll Articles