getTarget

inline fun <T> JoinPoint.getTarget(): T(source)

Returns JoinPoint.target cast to T.

Useful when advice code needs to interact with the receiver beyond the generic Any? type.

Example

@Before(target = [Audited::class])
fun doBefore(jp: JoinPoint) {
val service = jp.getTarget<UserService>()
service.recordAccess()
}

Throws

if the target cannot be cast to T.

if the target is null (top-level or companion-object function).