Hello, first time posting here after some time lurking JME is awesome.
I was looking about the API for easy ways to find Spatials with certain userdata. I couldn’t find anything so I did a generic method that takes in a Comparable<?> value and looks in each spatial for that particular userdata (using a visitor)
Are there any built-in alternatives?
Like that I would have to need to cast the values no? Maybe I was missing something.
This was the most general off the code solution I got to what I needed in the moment.
I couldn’t pass operators unless it’s some kind of enum I guess. I am now making something more generic.
Thank you.
You don’t need to cast to use .equals()… you don’t need to cast to use anything in the root class. Literally, you could remove the Comparable<?> from your code and it would still work with no other changes… but with that change it would support objects that aren’t Comparable.
Comparable is only for objects that can be sorted, ie: compared to one another for ordering.
Might I suggest doing some deeper Java tutorials sometime when you have a chance. They will cover this better than a forum thread here might.
Yeah sorry about it, will do.
Indeed Comparable<?> is not needed as you mention in this case but I do need the work for some cases. It’s looking good now.
Anyway what got me started was this simple example:
Sphere sphere = new Sphere(64, 64, dn.getUserData(“radius”));
needs to be?
Sphere sphere = new Sphere(64, 64, (Float)dn.getUserData(“radius”));
was wondering if I was doing something wrong.