Class GoodGrandchild
- java.lang.Object
-
- com.github.rvesse.airline.examples.inheritance.Parent
-
- com.github.rvesse.airline.examples.inheritance.Child
-
- com.github.rvesse.airline.examples.inheritance.GoodGrandchild
-
- All Implemented Interfaces:
ExampleRunnable
@Command(name="good-grandchild", description="A legal command which overrides an option defined by a parent") public class GoodGrandchild extends Child
When inheriting from existing classes it is possible to override previously defined options but only if you are explicit about it. In this case Airline uses the bottom-most definition of the option as the effective definitionNote that any values set for options are propagated to all declarations in the inheritance tree since an ancestor class will not have access to fields set in the descendants.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanparentWe can override the definition of an existing option under certain conditions:arity,nameandoptionTypeare unchanged Type is same or a valid narrowing conversion exists from the inherited option type to the overridden type You explicitly declareoverrideto betrueand the inherited option does not definesealedto betrue
-
Constructor Summary
Constructors Constructor Description GoodGrandchild()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidmain(java.lang.String[] args)
-
-
-
Field Detail
-
parent
@Option(name="--parent", description="An option can be overridden if we are explicit about it", override=true) private boolean parent
We can override the definition of an existing option under certain conditions:arity,nameandoptionTypeare unchanged- Type is same or a valid narrowing conversion exists from the inherited option type to the overridden type
- You explicitly declare
overrideto betrueand the inherited option does not definesealedto betrue
In practise this means you can change some informative properties of the option such as the title and description. You can also choose to make it visible/hidden and required/not required as desired.
Note that often if you find yourself needing to override options frequently then this can be indicative of poorly thought out option inheritance in which case using modules may be a better option. See
Modulesfor an example of this.
-
-