|
|
|
|
|
Re: Constructing instances of value-bound classes [message #567438 is a reply to message #506954] |
Tue, 12 January 2010 12:59  |
Eclipse User |
|
|
|
Stephan Herrmann wrote on Mon, 11 January 2010 09:09
> Eugene Hutorny wrote:
> > Another related question - from the documentation I got impression that
> > the generic's wildcards can be used for the value bound types, something
> > like:
> >
> > Person<?> woman = new Person<@Gender.Female>("Lisa");
> >
> > but I did not succeed with this. Is this feature supported?
>
> Sorry, no. Currently, the "?" is only used in the standard Java way
> to denote an unknown type, not an unknown value.
>
> Stephan
I should add a simple pattern for achieving the same as saying "Person<?>":
public interface IPerson {
String getName();
}
public class Person<Gender gender> implements IPerson {
// details as before
}
IPerson woman = new Person<@Gender.Female>("Lisa");
This gives us a gender-aware class plus a gender-unaware interface.
If the same pattern should be applied to roles (regarding the implicit dependency
on the enclosing team instance), the interface is declared outside the team
as to provide a plain-Java view of a role (using the example of a contemporary thread):
public interface IIndividual {
void eat(Food food);
}
public team class Mammals {
public class Individual implements IIndividual {
// details omitted
}
public class Female extends Individual { /* ... */ }
}
final Mammals mammals = new Mammals();
IIndividual individual = Female<@mammals>();
cheers,
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.27189 seconds