package org.mypackage;
class Foo {
public static void main(String[] args) {
Bar casted = (Bar) args[0]; // want to detect this casting action!
}
}
如何编写切入点来表示转换操作,不仅针对Foo
类,还针对org.mypackage
中的任何类?
背景:因此,Hibernate 5 + Spring Data JPA要求强制转换具有继承性的实体:
if (isInstanceOfMyEntity(someEntity)) {
// formerly, this was sufficient:
// MyEntity myEntity = (MyEntity) someEntity;
// now, this is required *everywhere* it is casted:
MyEntity myEntity = (MyEntity) Hibernate.unproxy(someEntity);
...
}
...,在大型代码库中,考虑到很多地方,这很容易让人担心。因此,如果有可能编写一个方面/切入点至少可以检测到它,那么我们至少可以将其记录下来,并在测试中确定需要解决问题的位置。
[@ Vlad-Mihalcea在此问题How to convert a Hibernate proxy to a real entity object中建议使用此技术。
我希望能够编写一个方面来检测何时在org.mypackage类之一中投射某些内容。包org.mypackage;类Foo {public static void main(String [] args){Bar ...
您不能拦截演员表。