1

I'm writing a class and I find it helpful to have functions I have yet to implement in the class I'm working in, so if I'm making a stack for ints I could write something like:

public class Stack
{
    ...

    private void push(int n) {}

    private int pop() {}

    ...
}

just as a reminder of functionality I'm supporting and organizational purposes. Is this somehow possible? I keep getting compile time errors when I try.

The functionality I'm looking for is similar to python's pass statement like:

def f():
    pass
jtht
  • 793
  • 2
  • 10
  • 19
  • Not if you have a return type other than `void`. You could have just tried it. – Sotirios Delimanolis Feb 13 '14 at 04:36
  • See this answer: http://stackoverflow.com/a/5607373/426028 Define your own NotImplementedException class and throw it from within your not-implemented methods. – agentnega Feb 13 '14 at 04:41
  • Alternatively, comment out the line. Most IDE's make commenting easy; simply put your cursor in or highlight the line(s) you want to comment and press `ctrl /` to toggle comments. – Justin Feb 13 '14 at 04:42

1 Answers1

1

The conventional way, which the Netbeans IDE will do automatically when implementing an interface or extending an abstract class to provide placeholders, is to do:

private void push(int n) {
    throw new UnsupportedOperationException("not implemented yet");
}
Brian Roach
  • 76,169
  • 12
  • 136
  • 161
  • +1 Eclipse uses default template of some variation of `return null;` which I think is a bad thing and usually replace my template by throwing `UnsupportedOperationException` – Miserable Variable Feb 13 '14 at 04:46
  • Yeah, I haven't used eclipse for ages. I'll edit a specify netbeans since this is exactly what it does – Brian Roach Feb 13 '14 at 04:47