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 
3
  • Not if you have a return type other than void. You could have just tried it. Commented Feb 13, 2014 at 4:36
  • See this answer: stackoverflow.com/a/5607373/426028 Define your own NotImplementedException class and throw it from within your not-implemented methods. Commented Feb 13, 2014 at 4: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. Commented Feb 13, 2014 at 4:42

1 Answer 1

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"); } 
Sign up to request clarification or add additional context in comments.

2 Comments

+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
Yeah, I haven't used eclipse for ages. I'll edit a specify netbeans since this is exactly what it does

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.