|
Re: Problems with Brole playedBy Arole [message #514181 is a reply to message #514089] |
Fri, 12 February 2010 17:39 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
OK, regarding the compile error I have an answer.
To make the message less confusing I first refactored the code,
so that variable names are unique. I did this by changing the variables
in TheTest:
- ateam -> aTeam, bteam -> bTeam....
Now we see that TheTest.aTeam is not the same variable
as Bteam.ateam, the compiler now reports:
The method lift(Arole<@bTeam.ateam>) in the type Bteam is not applicable for the arguments (Arole<@aTeam>)
Indeed the compiler doesn't see that bTeam.ateam == aTeam.
This is because passing the constructor arg in "bTeam = new Bteam(aTeam)"
is not tracked by the type checker. Luckily, there is language support
to help the compiler to see exactly this identity.
Change Bteam to start like this:
public team class Bteam<Ateam ateam> {
public Bteam() {
super();
}
...
This makes the team itself a value dependent class
(cf. http://www.objectteams.org/def/1.3/s9.html).
Given that now the parameter ateam is a property of the
type Bteam, we need to rewrite TheTest like this:
public class TheTest {
final Ateam aTeam = new Ateam();
final Bteam<@aTeam> bTeam = new Bteam<@aTeam>();
final Cteam cteam = new Cteam();
final Bteam<@cteam> dteam = new Bteam<@cteam>();
final Aclass aclass = new Aclass();
...
Note, that aTeam is still passed into the creation of bTeam,
however, now in a position that the compiler can evaluate,
so that it "knows" that bTeam.ateam == aTeam.
Does this make sense to you, or should I explain more?
-> The code now compiles fine even with the "problematic" lines.
It can be executed, but then fails with the ClassCastException
you reported. I'll look into that next.
|
|
|
|
|
|
Re: Problems with Brole playedBy Arole [message #568093 is a reply to message #514089] |
Fri, 12 February 2010 17:39 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
OK, regarding the compile error I have an answer.
To make the message less confusing I first refactored the code,
so that variable names are unique. I did this by changing the variables
in TheTest:
ateam -> aTeam, bteam -> bTeam....
Now we see that TheTest.aTeam is not the same variable
as Bteam.ateam, the compiler now reports:
The method lift(Arole<@bTeam.ateam>) in the type Bteam is not applicable for the arguments (Arole<@aTeam>)
Indeed the compiler doesn't see that bTeam.ateam == aTeam.
This is because passing the constructor arg in "bTeam = new Bteam(aTeam)"
is not tracked by the type checker. Luckily, there is language support
to help the compiler to see exactly this identity.
Change Bteam to start like this:
public team class Bteam<Ateam ateam> {
public Bteam() {
super();
}
...
This makes the team itself a value dependent class
(cf. http://www.objectteams.org/def/1.3/s9.html).
Given that now the parameter ateam is a property of the
type Bteam, we need to rewrite TheTest like this:
public class TheTest {
final Ateam aTeam = new Ateam();
final Bteam<@aTeam> bTeam = new Bteam<@aTeam>();
final Cteam cteam = new Cteam();
final Bteam<@cteam> dteam = new Bteam<@cteam>();
final Aclass aclass = new Aclass();
...
Note, that aTeam is still passed into the creation of bTeam,
however, now in a position that the compiler can evaluate,
so that it "knows" that bTeam.ateam == aTeam.
Does this make sense to you, or should I explain more?
-> The code now compiles fine even with the "problematic" lines.
It can be executed, but then fails with the ClassCastException
you reported. I'll look into that next.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03486 seconds