The code:
interface Property<T>
{
T get();
}
class BoolProperty implements Property<Boolean>
{
@Override
public Boolean get()
{
return false;
}
}
class StringProperty implements Property<String>
{
@Override
public String get()
{
return "hello";
}
}
class OtherStringProperty implements Property<String>
{
@Override
public String get()
{
return "bye";
}
public String getSpecialValue()
{
return "you are special";
}
}
is used by my class:
class Result<P extends Property<X>, X>
{
P p;
List<X> list;
}
As you see it has two type parameters P
and X
. Despite of that the X
can always be deduced from P
but the language requires me to supply both:
Result<BooleanProperty, Boolean> res = new Result<BooleanProperty, Boolean>();
Is there any trick to get rid of the X
type parameter? I want just use
Result<BooleanProperty> res = new Result<BooleanProperty>();
Also, I don't want lose type information and use it as:
Result<OtherStringProperty> res = new Result<OtherStringProperty>();
String spec = res.p.getSpecialValue();
String prop = res.list.get(0);