mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 20:17:25 +00:00
Update With.html
## Summary The current sentence fragment `Lombok's own <a href="/features/constructor"><code>@AllArgsConstructor</code></a>` does not fully clarify the author's intention, which I presume is to recommend using `@AllArgsConstructor`.
This commit is contained in:
1 parent
3c54d73353
commit
3369e0ffc7
1 file changed
+1
-1
@@ -14,7 +14,7 @@
|
||||
</p><p>
|
||||
For example, if you create <code>public class Point { private final int x, y; }</code>, setters make no sense because the fields are final. <code>@With</code> can generate a <code>withX(int newXValue)</code> method for you which will return a new point with the supplied value for <code>x</code> and the same value for <code>y</code>.
|
||||
</p><p>
|
||||
The <code>@With</code> relies on a constructor for all fields in order to do its work. If this constructor does not exist, your <code>@With</code> annotation will result in a compile time error message. Lombok's own <a href="/features/constructor"><code>@AllArgsConstructor</code></a>. As <a href="/features/Value"><code>Value</code></a> will automatically produce an all args constructor as well, you can use that too. It's of course also acceptable if you manually write this constructor. It must contain all non-static fields, in the same lexical order.
|
||||
The <code>@With</code> relies on a constructor for all fields in order to do its work. If this constructor does not exist, your <code>@With</code> annotation will result in a compile time error message. You can use Lombok's own <a href="/features/constructor"><code>@AllArgsConstructor</code></a>, or as <a href="/features/Value"><code>Value</code></a> will automatically produce an all args constructor as well, you can use that too. It's of course also acceptable if you manually write this constructor. It must contain all non-static fields, in the same lexical order.
|
||||
</p><p>
|
||||
Like <a href="/features/GetterSetter"><code>@Setter</code></a>, you can specify an access level in case you want the generated with method to be something other than <code>public</code>:<br /> <code>@With(level = AccessLevel.PROTECTED)</code>. Also like <a href="/features/GetterSetter"><code>@Setter</code></a>, you can also put a <code>@With</code> annotation on a type, which means a <code>with</code> method is generated for each field (even non-final fields).
|
||||
</p><p>
|
||||
|
||||
Reference in new issue
Block a user