随着kotlin越来越流行,项目引入kotlin混编可能性越来越大,有时可能需要业务判断是java编写的还是是kotlin编写,今天折腾了一下,终于搞定编码过程如何判断一个类是java类还是kotlin类了
static boolean isKtClass(Object object) {
Annotation[] annotations = object.getClass().getAnnotations();
if (annotations == null) {
return false;
}
for (int i = 0; i < annotations.length; i++) {
if (annotations[i].toString().contains("kotlin")) {
return true;
}
}
return false;
}
原创文章,作者:wure,如若转载,请注明出处:https://blog.ytso.com/tech/272350.html