I am using kundera to define my data model which will be stored in hbase. There is a class called "Task" which should have a generic type of submission like so:
public class Task {
...
Object submission;
}
The submission could be of any type since I want to keep it generic.
So my question is: 1. Is the above method a good practice? Will it work? 2. What is the best way to achieve this?
Having a generic type is a good idea. Yes, it should work. However, the type you have provided is not generic. Here is an example of a generic type:
public class Task<T> {
T submission;
// You can now use T as a class (but not with `new` or some other things)
public T getSubmission() { return submission; }
public void setSubmission(T new) { submission = new; }
public Task(T t) { setSubmission(t); }
// etc.
}
Then, you can make a Task
of a certain type, for example:
Task<String> stringTask = new Task<String>("hello");
Take a look at the Generics Tutorial for more information.