aspectj中call和execution的區別

2021-08-31 20:15:24 字數 1669 閱讀 1580

call

和 execution

的指示符分別為

call ( method-signature )、 execution ( method-signature ),匹配方法簽名的方法或建構函式的執行。 對於 call 來說,呼叫的連線點位於方法呼叫點的呼叫**處;對於 execution 來說,執行的連線點位於方法執行的位置。也就是說, call 和 execution 的重要區別在於它們傳遞了哪些型別給 aspectj 編譯器以用來與 aspect 進行鏈結。

通常,我們在使用

call

和 execution

時,從效果上來看並不會覺察出二者的區別。下面給出乙個例子說明

call

和 execution

的執行時機及區別。

myaspectj中的**:

public aspect myaspectj }

test中的**:

public class test

public void f()

}test1中的**:

public class test1  

public static void main(string args)

}test1中main函式的執行結果:

before call f()

com.gaojian.aspectj.test.test@141d683

com.gaojian.aspectj.test.test@141d683

cflowtest.f();

**************************************

before call f()

com.gaojian.aspectj.test.test1@16a55fa

com.gaojian.aspectj.test.test@141d683

cflowtest.f();

從輸出可以看到,在 execution 中,thistarget指向同乙個類。在 call 中,thistarget不是指向同乙個類

execution

與 call

還有一點很重要的區別。對於繼承類來說,如果它沒有覆蓋父類的方法,那麼

execution

不會匹配子類中沒有覆蓋父類的方法。比如說我們有乙個類

b 繼承於

a ,但沒有覆蓋

a 類的

foo()

,那麼對於

b 的例項的

foo()

方法,

execution(* b.foo())

將不會被匹配。

做個總結,如果想跟蹤連線點的內部**運**況可以考慮使用

execution

,但如果你只關心連線點的簽名(比如你使用第三方庫或是標準

api ),則使用

call

Oracle中執行儲存過程call和exec區別

在sqlplus中這兩種方法都可以使用 exec pro name 引數1.call pro name 引數1.區別 1.但是exec是sqlplus命令,只能在sqlplus中使用 call為sql命令,沒有限制.2.儲存過程沒有引數時,exec可以直接跟過程名 可以省略 但call則必須帶上 s...

Javascript中call和apply的區別

如下 function add a,b function reduce a,b add.call reduce,1,3 將add方法運用到reduce,結果為4 如下例 如下 複製 function b b window b.call window b.call a 2,3 a 再看乙個複雜的例子 ...

call 和call的區別

語法 func.call thisarg,arg1,arg2,thisarg表示函式執行時使用的this值,arg1,arg2,是引數列表,表示函式執行時需要的引數。在建構函式繼承的示例中 父類 function person name,age 子類 function student name,ag...