Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| research:mao:subtyping [2011/06/17 13:36] – ebodden | research:mao:subtyping [2011/06/17 13:36] (current) – ebodden | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | Here we propose a syntax and semantics for subtyping... | ||
| + | Consider the following JPIs with the stated subtyping relationship: | ||
| + | |||
| + | jpi void A(Object o); | ||
| + | jpi void B(Object a, Object b) extends A(b); //extend A, equating b with o above | ||
| + | | ||
| + | The semantics is here that B is a special kind of A that exposes more context: the additional parameter '' | ||
| + | |||
| + | Now consider an advice advising joinpoints of type A: | ||
| + | |||
| + | void around A(Object s) { | ||
| + | //do something | ||
| + | proceed(" | ||
| + | } | ||
| + | | ||
| + | If this advice received a joinpoint of type B as an input this has the semantics that '' | ||
| + | |||
| + | ===== Invariant return and argument types ===== | ||
| + | |||
| + | We can**not** allow covariant return types or contravariant argument types because of the same signature is currently being used for calling (1) the around advice and (2) calling '' | ||
| + | |||
| + | The following shows an example test case for return types in CJPs: | ||
| + | |||
| + | < | ||
| + | import java.util.*; | ||
| + | |||
| + | public aspect CheckReturnTypesIncorrect { | ||
| + | |||
| + | static void wrongActualReturnType() { | ||
| + | Set s = exhibit JPHashSet { | ||
| + | return new Object(); //Error: Object is no HashSet | ||
| + | }; | ||
| + | } | ||
| + | |||
| + | static void wrongDeclaredReturnType() { | ||
| + | HashSet s = exhibit JPSet { //Error: Set is no HashSet | ||
| + | return new HashSet(); | ||
| + | }; | ||
| + | } | ||
| + | |||
| + | public static void main(String args[]) { | ||
| + | wrongActualReturnType(); | ||
| + | wrongDeclaredReturnType(); | ||
| + | } | ||
| + | |||
| + | joinpoint Set JPSet(); | ||
| + | |||
| + | joinpoint HashSet JPHashSet(); | ||
| + | |||
| + | }</ | ||

