#### §2.3.4.(d) Mismatching role

In cases of potential ambiguity another runtime error may occur: a mismatching role is encountered when a role is found in the cache, which is not conform to the required type. This happens, if the base object has previously been lifted to a type that is incompatible with the currently requested type.

##### Effect:

This is reported by throwing a `org.objectteams.WrongRoleException`.

##### Example code (Mismatching Role):

1

    import org.objectteams.LiftingFailedException;

2

    					team class MyTeam {

3

      public class SuperRole playedBy MyBase {...}

4

      public class SubRoleA extends SuperRole {...}

5

      public class SubRoleB extends SuperRole {...}

6

7

      public void useRoleA(MyBase as SubRoleA r) throws LiftingFailedException {...}

8

      public void useRoleB(MyBase as SubRoleB r) throws LiftingFailedException {...}

9

    }

10

    // plus these calls:

11

    MyTeam mt = new MyTeam();

12

    MyBase b = new MyBase();

13

    mt.useRoleA(b); // creates a SubRoleA for b

14

    mt.useRoleB(b); // finds the SubRoleA which is not compatible

15

                    // to the expected type SubRoleB.

From the second item of §2.3.4.(a) follows, that for binding ambiguities different role hierarchies are analyzed in isolation. For this analysis only those role classes are considered that are bound to a base class (directly using `playedBy` or by inheriting this relation from another role class). I.e., two role classes that have no common bound super role will never cause any ambiguity.