I want to design a library that takes as input arrays of varying dimension and variable type, then processes them in different pipelines according to a preferences file. The idea is that the switch method will choose one of these pipelines, and an overload will handle the varying types.
I have written some toy code that abstracts the problem. I think if I could get this code to work I would know how to design my project.
I have a base class Foo which takes an argument of either Float or Double type, and an integer for preferred pipeline. Here is the code I have written for this. Note it does not compile.
I then have two pipeline classes Bar1 and Bar2 . These both compile.
The desired output is
Bar 1 Double
Bar 1 Float
Bar 2 Double
Bar 2 Float
However the compiler isn't having any
I would really like to do this some more elegant way than casting the Object. Am I stuck casting the Object or is there a more elegant way to handle these cases?
Unfortunately the Bar methods are somehow not right. The void keyword should not be there and those are constructors not methods. When they are constructors you get the compiler message seen there. I must have posted the wrong vim register but don't see a way to edit my post.
But, I think your answers would still be the same. It looks like the most elegant solution is probably to take an Object argument and then using getClass() cast it and pass it on to the relevant subtype and method. Thanks!
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
a bit of art, as a gift, the permaculture playing cards