-
Notifications
You must be signed in to change notification settings - Fork 44
@AutoGenMethodStub
With this annotation you can avoid cluttering your code with empty methods that an interface forces you to implement. Just implement the ones you need and lombok will create stubs for the rest.
import lombok.AutoGenMethodStub;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@AutoGenMethodStub
class AutoGenMethodStubExample implements MouseListener {
public void mouseExited(MouseEvent e) {
// defined
}
}
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
class AutoGenMethodStubExample implements MouseListener {
public void mouseExited(MouseEvent e) {
// defined
}
public void mouseEntered(java.awt.event.MouseEvent arg1) {
}
public void mouseReleased(java.awt.event.MouseEvent arg1) {
}
public void mousePressed(java.awt.event.MouseEvent arg1) {
}
public void mouseClicked(java.awt.event.MouseEvent arg1) {
}
}
This annotation instructs lombok to find all unimplemented methods of the annotated type and create method stubs for all of them. If the return type of the method is void
the method body of the stub will be empty. Otherwise the default value[1] of the return type will be returned.
By default the stub method will return the default value of the return type.
If you prefer that an java.lang.UnsupportedOperationException
is thrown, use: @AutoGenMethodStub(throwException = true)
.
import lombok.AutoGenMethodStub;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@AutoGenMethodStub(throwException = true)
class AutoGenMethodStubExample implements MouseListener {
public void mouseExited(MouseEvent e) {
// defined
}
}
class AutoGenMethodStubExample implements MouseListener {
public void mouseExited(MouseEvent e) {
// defined
}
//...
public void mouseClicked(java.awt.event.MouseEvent arg1) {
throw new java.lang.UnsupportedOperationException("This method is not implemented yet.");
}
}
[1] The Java™ Language Specification; 4.12.5. Initial Values of Variables
I am not able to run @Action. If I provide Action1 implementation it works.
implementation private static Action1 println() { return new Action1() { public void apply(final Object o) { System.out.println(o); } };
pom : com.github.peichhorn lombok-pg 0.11.3
<dependency>
<groupId>com.github.peichhorn</groupId>
<artifactId>lombok-pg</artifactId>
<version>0.11.3</version>
<classifier>runtime</classifier>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>