In Java what is the use case of .createAnd and .asExerciseCommand?

Hi team,

In Java, what is the use case of CreateAnd (CreateAnd) and
asExerciceCommand (ExerciseCommand)

Do you have any example code on how you would use these ?

Thanks and regards,


CreateAnd is used to create createAndExercise commands. You use it like template.createAnd(r.exerciseChoice(…) You can see a concrete example in the tests.

asExerciseCommand is just a glorified wrapper around isInstanceOf. If you already have an ExerciseCommand it doesn’t make sense it but you could call it if you have a Command and want to know if it’s an exercise command. But I don’t think that’s a particularly common usecase so unless there is something specific you are trying to do I’d recommend to just ignore it. The implementation is literally a wrapper around isInstanceOf so you can also just fallback to that.


Please don’t fall back to casting. We are strongly considering a design change that may, among other things, make it so that asExerciseCommand works, but (ExerciseCommand) does not work.

But, indeed, you should not have to use it at all, and we might even deprecate the former. If you do have a good use case for it, let us know.