Collision Result: type parameters of T cannot be determined

Hi everyone,



I’m momentarily working, together with some colleagues, on a little game where you have to shoot at some objects in order to trigger some events. Using the collision-detection described in the tutorial, I’ve managed to detect which model was selected by the user and compiling the program within jmonkey works flawlessly. But as soon as I try to build the project for deployment, i get the following error.



type parameters of T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object

return(node.getUserData(name));



In order to retrieve the Spatial with the user-data I have to iterate through the parent objects of the closest collisions until I find the one with the right userdata (of type int). I know, that this kind of error is usually thrown when the generic type of a List or Hashmap is not specified and the compiler does not know how to resolve the type. I’ve also looked into the JMonkey-Documentation and found that this method is somewhat using generic data-types, but i don’t know how the set this type.



Maybe I’m just missing some very stupid little detail, but I’ll be very thankful for any hint into the right direction.

Make a variable instead of returning the return value of getUserData. You have to know the type of the data through its name really. The name should be the defining thing about the UserData, not the type. If you have to, make your own type using a Savable and add any functionality you need there.

I am not sure if I understand what you are trying to say…

I store the userdata using ‘…getGameSpatial().setUserData(“student”,i);’ where i is simply the index (int) of the spatial in the game. To find the correct parent, I execute this method



public int retrieveUserdata(Node node, String name){



if(node.getUserData(name) != null){

int i = node.getUserData(name);

return(i);

}

else

{

return(this.retrieveUserdata(node.getParent(), name));

}

}



What exactly do you mean by “…make a variable…”

The return type of getUserData is not defined, you cannot use it this way.

how do I define it?

int i = (Integer) node.getUserData(name);



The user data is stored in a pair of String and Object so you will always retrieve an Object that you have to cast manually.

No you don’t have to cast manually, its defined by the type of the value you assign it to, that is why the return value is not defined. So all of these are valid:

[java]

Integer i = spatial.getUserData(“name”);

Boolean b = spatial.getUserData(“name”);

Spatial s = spatial.getUserData(“name”);

[/java]

At the moment UserData can only be integers, floats, booleans, strings or any kind of Savable.

2 Likes

Damn. I knew that it was something absolutely stupid I forgot. I’ve tried to cast it with (int) but off course not with the actual class Integer self-facepalm . Thats so embarrassing…



Thank you very much for your help.

At the moment UserData can only be integers, floats, booleans, strings or any kind of Savable.


Then it's luck that my programs didn't need other data until now^^ Thanks for pointing that out.

No you don’t have to cast manually,


At least it works either way (so I was at least not completely wrong^^)