I wanna define an interface, like
public interface Visitor <ArgType, ResultType, SelfDefinedException> {
public ResultType visitProgram(Program prog, ArgType arg) throws SelfDefinedException;
//...
}
during implementation, selfDefinedException varies. (selfDefinedException as a generic undefined for now) Is there a way to do this?
Thanks
You just need to constrain the exception type to be suitable to be thrown. For example:
interface Visitor<ArgType, ResultType, ExceptionType extends Throwable> {
ResultType visitProgram(String prog, ArgType arg) throws ExceptionType;
}
Or perhaps:
interface Visitor<ArgType, ResultType, ExceptionType extends Exception> {
ResultType visitProgram(String prog, ArgType arg) throws ExceptionType;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With