tlf30 / monkey-netty

A implementation of a server-client communication system for jMonkeyEngine using Netty.IO that utilizes both TCP and UDP communication.
MIT License
12 stars 5 forks source link

17-setAttribute-in-interface #18

Closed oxplay2 closed 3 years ago

oxplay2 commented 3 years ago
oxplay2 commented 3 years ago

also added

public <T> T getAttribute(String key, Class<T> castClass);

into interface to allow more clean casting way. If you have something against it, please tell.

tlf30 commented 3 years ago

I just got back home, I will review today. Thank you for the addition.

tlf30 commented 3 years ago

I think this is great the way it is, but I have two items to run by you prior to merging in. First, the JME engine uses set/getUserData, perhaps we can rename attributes to user data to be more consistent with the engine? While the outside engine uses the term attributes so that is where that came from, I think it would be best for this library to maintain consistency with jme. Second, jme uses a bound generic type on the <T>getUserData() function where they do not pass in the class type.

node.setUserData("hi", 7);
int i = node.<Integer>getUserData("hi");
System.out.println(i);

While I generally prefer how you have it now, where the class type is passed in as an argument, for the sake of consistancy with the engine, should we make function a generic function without the type as a parameter? This would be as simple as removing the Class<T> castClass from the parameters of the function.

oxplay2 commented 3 years ago
tlf30 commented 3 years ago

Looks good, thank you!