Java Reference
In-Depth Information
}
}
Compliant Solution ( final Class)
This compliant solution declares the LicenseType class final so that its methods cannot
be overridden:
final class LicenseType {
// ...
}
Noncompliant Code Example
This noncompliant code example consists of a Widget class and a LayoutManager class
containing a set of widgets:
Click here to view code image
public class Widget {
private int noOfComponents;
public Widget(int noOfComponents) {
this.noOfComponents = noOfComponents;
}
public int getNoOfComponents() {
return noOfComponents;
}
public final void setNoOfComponents(int noOfComponents) {
this.noOfComponents = noOfComponents;
}
public boolean equals(Object o) {
if (o == null || !(o instanceof Widget)) {
return false;
}
Widget widget = (Widget) o;
return this.noOfComponents == widget.getNoOfComponents();
}
@Override
public int hashCode() {
int res = 31;
res = res * 17 + noOfComponents;
return res;
Search WWH ::




Custom Search