1. kotlin學(xué)習(xí)demo
1.4 Kotlin的inline內(nèi)聯(lián)函數(shù)
1.5 Kotlin系列之let苟径、with休涤、run蛔外、apply、also函數(shù)的使用
補(bǔ)充{
let、with、run、apply、also
var 我:Any
wo.also{
fun T.also(block: (T) -> Unit): T { block(this); return this }
表述 我創(chuàng)建一個(gè)方法 然后方法內(nèi)部調(diào)用我 用it 返回我
}
我.apply{
fun T.apply(block: T.() -> Unit): T { block(); return this }
表達(dá) 創(chuàng)建一個(gè)方法 該方法來自我(持有我的引用)返回我
}
我.let{
fun <T, R> T.let(block: (T) -> R): R = block(this)
表述 我創(chuàng)建一個(gè)方法 然后方法內(nèi)部調(diào)用我 用it 返回代碼最后值
}
我.run{
fun <T, R> T.run(block: T.() -> R): R = block()
創(chuàng)建一個(gè)方法 該方法來自我(持有我的引用)返回代碼最后值
}
with(我){
fun <T, R> with(receiver: T, block: T.() -> R): Rreceiver.block()
表達(dá) 創(chuàng)建一個(gè)方法 該方法來自我(持有我的引用) 返回代碼最后值
}
2. kotlin mvp
3.kotlin學(xué)習(xí)demo
4.防止過快點(diǎn)擊 面向切面
5.面向切面 學(xué)習(xí)(運(yùn)行時(shí)動(dòng)態(tài)權(quán)限申請(qǐng))
補(bǔ)充:切點(diǎn)表達(dá)式:execution (* com.lqr...(..))叠荠。
execution(<修飾符模式>? <返回類型模式> <方法名模式>(<參數(shù)模式>) <異常模式>?)
//匹配所有的public方法
execution(public * *(..))
//匹配所有以"to"結(jié)尾的方法
execution(* *to(..))
//匹配com.lqr包下及其子包中以"to"結(jié)尾的方法
//注意-->
// 子包后面是兩個(gè)點(diǎn) com.lqr..
// 包后面是一個(gè)com.lqr.
//*后面必須加空格 * com
execution(* com.lqr..*to(..))
//匹配com.lqr包下所有返回類型是int的方法
execution(int com.lqr.*(..))
//匹配com.lqr包及其子包中的所有方法,當(dāng)方法拋出異常時(shí)扫责,打印"ex = 報(bào)錯(cuò)信息"榛鼎。
@AfterThrowing(value = "execution(* com.lqr..*(..))", throwing = "ex")
@Pointcut("execution(* com.lqr.androidaopdemo.MainActivity.test(..))")
public void pointcut() {
}
@Before("pointcut()")
public void before(JoinPoint point) {
System.out.println("@Before");
}
@Around("pointcut()")
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("@Around");
}
@After("pointcut()")
public void after(JoinPoint point) {
System.out.println("@After");
}
@AfterReturning("pointcut()")
public void afterReturning(JoinPoint point, Object returnValue) {
System.out.println("@AfterReturning");
}
@AfterThrowing(value = "pointcut()", throwing = "ex")
public void afterThrowing(Throwable ex) {
System.out.println("@afterThrowing");
System.out.println("ex = " + ex.getMessage());
}
}
//耗時(shí)計(jì)算
@Around("pointcut()")
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
long beginTime = SystemClock.currentThreadTimeMillis();
joinPoint.proceed();
long endTime = SystemClock.currentThreadTimeMillis();
long dx = endTime - beginTime;
System.out.println("耗時(shí):" + dx + "ms");
}