Currently, I have something like this:-
public class MyHolder<T> {
private T value;
public MyHolder(T t) {
this.value = t;
}
public T getValue() {
return first;
}
public void setValue(T t) {
this.first = t;
}
}
With this, I can use it like this:-
MyBean bean = new MyBean();
MyHolder<MyBean> obj = new MyHolder<MyBean>(bean);
obj.getValue(); // returns bean
Instead of calling the getter/setter to be getValue()
and setValue(..)
, is it possible to "generify" that too?
Essentially, it would be nice to have it getMyBean()
and setMyBean(..)
, depending on the type passed in. Granted this is a very simple example, however if I create a generic holder class that takes N generic properties, then it would be nice to call it something meaningful instead of getValue1()
or getValue2()
, and so on.
Thanks.
No. There is no such feature in Java. I can't even imagine how it would look syntactically... void set<T>();
? And how would the getter / setter for for instance MyHolder<? extends Number>
look?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With