Java-NoOp icon indicating copy to clipboard operation
Java-NoOp copied to clipboard

Throws Exception on certain method

Open RoRoche opened this issue 8 years ago • 1 comments

Currently, Java-NoOp generates methods with default data type values.

On some case, it could be interesting to throw an exception to notify that it's a no-op object and it's not going to provide a valid behavior.

For example, here is an Employee interface:

@NoOp
public interface Employee {
    String name();

    void doCriticalStuff();
}

Dealing with a NoOpEmployee, there's no problem to get a empty name. But on my doCriticalStuff, it would be nice to throw a specific exception. For example, this could be the Employee interface:

@NoOp
public interface Employee {
    String name();

    @NoOpThrows(class=NoOpException.class, message="It's a no-op object, critical stuff can't be done properly")
    void doCriticalStuff();
}

generating:

public class NoOpEmployee implements Employee {
    // ...

    @Override
    public void doCriticalStuff() {
        throw new NoOpException("It's a no-op object, critical stuff can't be done properly");
    }
}

RoRoche avatar May 11 '17 16:05 RoRoche

Also the customed default return values of not void method could be indicated by annotationsđŸ™‚

imlk0 avatar Dec 14 '18 04:12 imlk0