Community
Participate
Working Groups
The current hasRole and getRole function only work on the exact dynamic type. It would be useful if they would also work on dynamic subtypes. This would make the methods equivalent to the regular java instanceof function.
To me this sounds like what we have, e.g., in this test case: http://www.objectteams.org/distrib/jacks/1.4.0/results/9.2.2-otjld-has-role-method-6.html This test case passes. What does it take to reproduce the problem?
Reproduce: public team class OuterTeam extends HasRoleFixTeam { public team class InnerTeam extends HasRoleFixTeam playedBy OuterBase { protected class SomeRole extends MyRoles playedBy InnerBase { } public void createRole(InnerBase as SomeRole b) { } public boolean habRole(InnerBase b){ boolean hasRole = InnerTeam.this.hasRole(b, MyRoles.class); System.out.println("hasRole: " + hasRole); return hasRole; } } public InnerTeam registerInnerTeam(OuterBase as InnerTeam o) { return o; } } Call: public class Main { public static void main(String[] args) { OuterBase ob = new OuterBase(); InnerBase ib = new InnerBase(); final OuterTeam ot = new OuterTeam(); InnerTeam<@ot> it = ot.registerInnerTeam(ob); it.createRole(ib); it.habRole(ib); } } The difference might be that the test uses a hierarchy of roles. In my example its a regular class.
(In reply to comment #2) > The difference might be that the test uses a hierarchy of roles. In my example > its a regular class. So it seems your (missing) class MyRoles is a regular class? That won't work and in this case you should actually just use hasRole(Object). Technical note: the second argument of hasRole(Object,Class) helps the runtime to find the appropriate internal role cache for searching, thus this class must be a role. I'll leave this bug open for now, to remind me that the documentation (OTJLD ยง6.1(a)) could be made more explicit about this constraint.
Documentation of reflective API has been clarified in r344 (source & OTJLD).
verified for M3 using 201005282024