Ryan Bohn
Ryan Bohn

Reputation: 21

In Netbeans, how do I type a non-existent method and have the method get generated automatically?

In other IDEs, I can type a method as if it existed, hit a key combination and the method is generated.

For example, I type:

public List<String> getIds() {
    int max = 4;
    return generateRandomArray(max);
}

As of now, the method generateRandomArray doesn't exist.

I then hit a key combination and it generates:

private List<String> generateRandomArray(int max) {
    return null;
}

How do I accomplish this in Netbeans without having to type the method manually?

Upvotes: 2

Views: 166

Answers (2)

Tom Neyland
Tom Neyland

Reputation: 6968

Additionally, there should be a little icon (with a lightbulb and red (!) ) on the left side of the text editor window, at the line that contains return generateRandomArray(max);

Click on it and click the option that reads:

Create method generateRandomArray(int) in MyPackage.MyClass.

Upvotes: 0

FRotthowe
FRotthowe

Reputation: 3662

Press alt+enter to show the auto fix options. Then, select create method ... (which should be the only option in most cases).

Upvotes: 1

Related Questions