User supports userType and userFunction by config:
{"userType": "com.user.Person", "userFunction": "com.user.userFunction"}
we expect to get data for user and feed data to userFunction:
public class DataConsumer<T> {
//get data from some place, such as kafka
T data;
}
process() {
String userType = userInput();
DataConsumer<userType> dataConsumer = new DataConsumer<userType>(); // error because generic class's type name don't support String or Class
userFunction(dataConsumer.data); // We get this function by reflection
}
// This is ok in the user side
userFunction(userType data) {
data;
}
How can I implement this function without error? If it is not possible, Is there another way?
At last, I use Object to stand all type names. But user must transform Object type to userType manually. Is there a better way?
{
String userType = userInput();
DataConsumer<Object> dataConsumer = new DataConsumer<Object>(); // ok
userFunction(dataConsumer.data);
}
userFunction(Object data) {
(userType)data;
}