views:

53

answers:

2

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?

+1  A: 

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

FRotthowe
alt+enter works with the specific example given. However, it doesn't work in the following instance.<code> public List<String> getIds() { List<String> list = new ArrayList<String>(); list.add(generateRandomId()); return list; }</code>
Ryan Bohn
A: 

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.

instanceofTom