The Ops developers tend to prefer the type-based invocations to the name-based ones, because the type-based ones are less error-prone. That is: the compiler will give you an error if you make a typo in the class name, but it won’t complain about a typo in a string.
That said, either one works.
Note that the
CreateANewOp example is very minimal, and does not define a new op interface. While you can write
ij.op().run(Narf.class, "whatever"), this ends up being a hardcoded call to the concrete
Narf op itself, which is rather pointless since the Ops matcher will always select the
Narf class. You may as well have just written plain old Java code at that point—e.g.
narf = new Narf(); narf.input = "whatever"; narf.run();. The point of the
GCD interface is so that multiple GCD ops can be written, which operate on different sorts of input parameters, and/or optimize for performance in different cases. Supposing we are too lazy to create a
Narf interface and then a
DefaultNarf concrete implementation, using
ops.run("narf", "...") here means that in theory, someone else could write a second
MyBetterNarf and also write
name = "narf" on it, and then the matcher will have options to work with.
Can you please share a pointer to your code? What really matters here are the dependencies of your project. To have access to
net.imagej.ops.Ops, you of course need to have
net.imagej:imagej-ops as a dependency of your project.
Nope, fortunately, these version numbers do not need to match precisely. If they did, we would have a huge problem as we would need to constantly update the
pom-scijava parent version across hundreds of components.
The simplest way to think of
pom-scijava is as a Bill of Materials—a “shopping list” of which component versions go together. The imagej-ops component itself depending on 14.0.0 means it inherits a BOM with versions older than the ones your component gets when it depends on 16.1.0. But that is usually not a problem. In any case, the fact that
net.imagej.ops.Op cannot be found is not related to this version difference.
P.S. Have you looked at the Extending ImageJ: Ops Jupyter notebook yet? Future plan is to migrate the
Adding new ops wiki page into that notebook.