Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ does not generate Copy Constructor

I try to automatically generate a copy constructor with IntelliJ, but I can not select this due to the box is grey out. How do I automatically generate a copy constructor by IntelliJ?

My Java Class

public class Parameter {
    public double mA;
    public double mB;
    public double mC;
    public double mD;
    public String mPath;

    public Parameter(double mA, double mB, double mC, double mD, String mPath) {
        super();
        this.mA = mA;
        this.mB = mB;
        this.mC = mC;
        this.mD = mD;
        this.mPath = mPath;
    }

    public Parameter(double mA, double mB, double mC, double mD) {
        this(mA, mB, mC, mD, "");
    }

    public double getA() {
        return mA;
    }
    public double getB() {
        return mB;
    }
    public double getC() {
        return mC;
    }
    public double getD() {
        return mD;
    }
    public String getPath(){
        return mPath;
    }
}

The button is grey out.

enter image description here

like image 219
Light Yagmi Avatar asked Jun 03 '15 01:06

Light Yagmi


People also ask

How do I select all constructors in Intellij?

You can use ⌘N (macOS), or Alt+Insert (Windows/Linux) for the Generate menu and then select Constructor , Getter , Setter or Getter and Setter .

How do I create a new method in Intellij?

Ctrl+O enables you to create default methods for methods you have to O verride. Alt+Insert enables you to generate commons methods (getters, setters, constructors etc...) If you call a method that does not exist, Alt+Enter opens a list of quick fixes.

What is copy constructor in Java?

A copy constructor in a Java class is a constructor that creates an object using another object of the same Java class. That's helpful when we want to copy a complex object that has several fields, or when we want to make a deep copy of an existing object.


2 Answers

What you can do is use "create constructor", select all the fields, then manually "tweak" that into a copy constructor :)

No plugin required anyway, and still mostly usable :)

like image 171
rogerdpack Avatar answered Sep 19 '22 15:09

rogerdpack


Generating a copy constructor functionality is not built into IntelliJ IDEA. Perhaps that Generate Copy Constructor action is coming from a plugin?

like image 41
Bas Leijdekkers Avatar answered Sep 16 '22 15:09

Bas Leijdekkers