Take a look at this code ( here )
abstract class EntityA {
AssocA myA;
abstract void meet();
}
abstract class AssocA {
int something;
abstract void greet();
}
class AssocAConcrete extends AssocA {
void greet() {
System.out.println("hello");
}
void salute() {
System.out.println("I am saluting.")
}
}
class EntityAConcrete extends EntityA {
void meet() {
System.out.println("I am about to meet someone");
((AssocAConcrete)myA).salute();
}
}
There are two parallel inheritance trees for the parent class and its associated class. The problem is line 23:
((AssocAConcrete)myA).salute();
This is pain, and I have such things throughout my code. Although this line is part of a specific Entity implementation, I need to be reminded that I want to use a specific AssocA implementation, AssocAConcrete.
Is there any annotation to declare this relationship? Or is there a better, more conversational Java way to express this design? Thank!
This is in response to @Dave because I want to put some code in ...
Interesting! Thus, the call will look something like this:
AssocAConcrete myAssoc = new Assoca();
EnitityA<T extends AssocA> myEntity = new EntityA<AssocAConcrete>();
myEntity.setAssoc(myAssoc);
myAssoc.salute();
Yes? It's really cool. I think I will use it!