Is there any convention to use for a dummy method body in Java? for testing purposes for example. Say I have a interface and a method should be implemented in a class implementing that interface but I don't want to implement it yet, what good dummy method body should I use that doesn't use unnecessary memory etc?
Asked
Active
Viewed 4,204 times
1
-
1For testing purpose, you can use mocking framework like Mockito. – tan9 Dec 08 '16 at 17:13
-
http://stackoverflow.com/questions/9984335/java-common-annotation-for-not-yet-implemented – Sotirios Delimanolis Dec 08 '16 at 17:13
-
@SotiriosDelimanolis my apologies, my search yeld no results but then again I only searched for dummy method body and similar stuff. – spacing Dec 08 '16 at 17:15
2 Answers
5
If you have a method which you haven't implemented yet I would
public void notImplementedYet() {
throw new UnsupportedOperationException("TODO");
}
I add the "TODO"
to indicate it may be supported in the future. Some methods throw this because it should never be supported.
BTW: I setup my IDE to place this exception as the default body for implementing methods.

Peter Lawrey
- 525,659
- 79
- 751
- 1,130
3
You can use Java 8's default methods.
See here. Basically, you define the implementation (or dummy method) in the interface itself.
public interface MyInterface {
default myDummyMethod() {
// nada
}
}

Andrei Sfat
- 8,440
- 5
- 49
- 69