我是 Sonar 和 Weld/CDI 的新手。我希望您能提供有关 Weld/CDI 的 LCOM4 分析结果的进一步建议。首先,我创建了一个简单的 java 类,如下所示: -
- - - - - - -资源 - - - - - - - -
interface MyInterface1 {
String getName();
void setName(String name);
}
interface MyInterface2 extends MyInterface1 {
String getPhone();
void setPhone();
}
public interface MyPublishedInterface extend MyInterface1, MyInterface2 {
//There is no any definition, it just a collected capabilities
//which will be published to other package. Some capabilities
//may be hidden and use internally.
}
abstract class MyBean1 implements MyInterface1 {
private String name;
@Override
public String getName() {
return this.name;
}
@Override
public void setName(String theName) {
this.name = theName;
}
}
abstract class MyBean2 extends MyBean1 implements MyInterface2 {
private String phone;
@Override
public String getPhone() {
return this.phone;
}
@Override
public void setPhone(String thePhone) {
this.phone= thePhone;
}
}
public class MyPublishedBean extends MyBean2 implements MyPublishedInterface {
//There is no any coding, it just a collected capabilities
//which will be published to other package. Some capabilities
//may be hidden and use internally.
}
@Named
@RequestScope
public class MyBackingBean {
@Inject
private MyPublishedInterface myPublishedInterface;
//-----the business method, setter and getter here.
}
- - - - - - -资源 - - - - - - - -
在我用声纳分析之后,它报告 MyPublishedBean 的 LCOM4>1 为
- getPhone()Ljava/lang/String;
- setName(Ljava/lang/String;)V
- setPhone(Ljava/lang/String;)V
- getName()Ljava/lang/String;
以前我曾经将所有方法标记为“最终”方法,没有任何关于 LCOM4 的提及。无论如何,系统向我显示了关于 Unproxyable 的异常,因为我的类包含最终方法。我已经删除了“决赛”,我遇到了 LCOM4 问题。
我不确定我是否对声纳、焊接/CDI、类/界面设计或所有这些感到困惑。你能帮忙提供进一步的建议吗?