简体   繁体   中英

Override constructor in all subclasses IntelliJ

I wanted to know if there is possibility to generate constructors for all subclasses in IntelliJ . I mean if i have many subclasses and somewhere in development stage I wanted to add new constructor , with a flag, for example. Is there a way to generate this constructor in all subclasses too?

I wanted to know if there is possibility to generate constructors for all
subclasses in IntelliJ?

The answer would be no and one of the reason would because it is design specific.

When you create a subclass and define a non default constructor in it you have the liberty to call any one of the overloaded superclass constructor from it. Which one would be design choice as initialization of superclass variables may depend on it. Never the less call to one of the overloaded super class constructor must be 1st statement of subclass constructor. If you do not provide any, call to default constructor of super class is inserted by default by the JVM. However in that case if your super class does not have default constructor(you have explicitly provided some parameterized constructor) then compiler error will occur.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM