java - Omitting one Setter/Getter in Lombok

ID : 10178

viewed : 16

Tags : javalombokjava

Top 5 Answer for java - Omitting one Setter/Getter in Lombok

vote vote

98

You can pass an access level to the @Getter and @Setter annotations. This is useful to make getters or setters protected or private. It can also be used to override the default.

With @Data, you have public access to the accessors by default. You can now use the special access level NONE to completely omit the accessor, like this:

@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) private int mySecret; 
vote vote

89

According to @Data description you can use:

All generated getters and setters will be public. To override the access level, annotate the field or class with an explicit @Setter and/or @Getter annotation. You can also use this annotation (by combining it with AccessLevel.NONE) to suppress generating a getter and/or setter altogether.

vote vote

71

Use the below code for omit/excludes from creating setter and getter. value key should use inside @Getter and @Setter.

@Getter(value = AccessLevel.NONE) @Setter(value = AccessLevel.NONE) private String mySecret; 
vote vote

68

vote vote

55

by default there're 2 argument groups in parser._action_groups: positional arguments and named arguments (titled 'optional arguments'). you can add your named optional arguments to the existing 'optional arguments' group, and required named arguments to a new 'required arguments' group. After that you can re-order groups:

import argparse  parser = argparse.ArgumentParser(description='Foo')  required = parser.add_argument_group('required arguments')  required.add_argument('-i','--input', help='Input file name', required=True) parser.add_argument('-o','--output', help='Output file name', default="stdout")  groups_order = {     'positional arguments': 0,     'required arguments': 1,     'optional arguments': 2 } parser._action_groups.sort(key=lambda g: groups_order[g.title])  parser.parse_args(['-h']) 

output:

usage: argparse_argument_groups.py [-h] -i INPUT [-o OUTPUT]  Foo  required arguments:   -i INPUT, --input INPUT                         Input file name  optional arguments:   -h, --help            show this help message and exit   -o OUTPUT, --output OUTPUT                         Output file name 

Top 3 video Explaining java - Omitting one Setter/Getter in Lombok

Related QUESTION?