Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Objectteams » Constructing instances of value-bound classes
Constructing instances of value-bound classes [message #506766] Sat, 09 January 2010 18:16 Go to next message
Eugene Hutorny is currently offline Eugene HutornyFriend
Messages: 109
Registered: January 2010
Senior Member
I have the following class:
public class Person<Gender gender>  {
	enum Gender { Male, Female }
	public Person(String name) {
		super();
		this.name = name;
	}
	protected final String name;
}


How can I create an instance of person? Smile
Re: Constructing instances of value-bound classes [message #506805 is a reply to message #506766] Sun, 10 January 2010 13:16 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1045
Registered: July 2009
Senior Member
Eugene Hutorny wrote on Sat, 09 January 2010 13:16
I have the following class:
public class Person<Gender gender>  {
	enum Gender { Male, Female }
	public Person(String name) {
		super();
		this.name = name;
	}
	protected final String name;
}


How can I create an instance of person? Smile


Theory says:
    Person<@Gender.Female> woman = new Person<@Gender.Female>("Lisa");


Practice says:
The above generates illegal byte code
(see https://trac.objectteams.org/ot/ticket/332)

What does it tell us?
Value-dependent types (other than roles) are not widely used and tested as of yet.

But:
A solution for Ticket 332 is on its way.

best,
Stephan

[Updated on: Sun, 10 January 2010 16:15]

Report message to a moderator

Re: Constructing instances of value-bound classes [message #506929 is a reply to message #506805] Mon, 11 January 2010 11:44 Go to previous messageGo to next message
Eugene Hutorny is currently offline Eugene HutornyFriend
Messages: 109
Registered: January 2010
Senior Member
Thanks for the clarification.
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?
Re: Constructing instances of value-bound classes [message #506954 is a reply to message #506929] Mon, 11 January 2010 14:09 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1045
Registered: July 2009
Senior Member
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
Re: Constructing instances of value-bound classes [message #507280 is a reply to message #506954] Tue, 12 January 2010 17:59 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1045
Registered: July 2009
Senior Member
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
Re: Constructing instances of value-bound classes [message #567438 is a reply to message #506954] Tue, 12 January 2010 17:59 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1045
Registered: July 2009
Senior Member
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
Previous Topic:OT/J Parser
Next Topic:Requests for backporting to 1.3.x/3.5.x?
Goto Forum:
  


Current Time: Thu Dec 18 05:49:56 GMT 2014

Powered by FUDForum. Page generated in 0.01664 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software