I have simple class:
public class A {
private int a;
private int b;
public A(int a) {
this.a = a;
}
}
And now I want to add int b
то constructors arguments and initialize class field with new argument . So it, finally, must be:
public A(int a, int b) {
this.a = a;
this.b = b;
}
So, if IDEA
(AndroidStudio
) have shortCut for it?
P.S. Same question for Eclipse
: Shortcut for adding fields to existing constructor
A constructor is a special method that is called whenever an object is created using the new keyword. It contains a block of statements that is used to initialize instance variables of an object before the reference of this object is returned by new.
To call one constructor from another constructor is called constructor chaining in java. This process can be implemented in two ways: Using this() keyword to call the current class constructor within the “same class”. Using super() keyword to call the superclass constructor from the “base class”.
A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created.
private
Alt+Enter
add constructor parametr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With