Methods Summary |
---|
public int | getValue()Getter for the property value.
return value;
|
public static void | main(java.lang.String[] args)Main demonstration method.
final FriendAccess one = new FriendAccess(5);
final FriendAccess two = new FriendAccess(5);
try {
two.setValue(25);
} catch (final IllegalArgumentException ex) {
System.out.println("Settign value to 25 through setter rejected");
}
one.someMethod(two);
System.out.println("Settign value to 25 through friend ALLOWED!!!");
System.out.println(two.getValue());
|
public void | setValue(int value)Setter for the property value. Doesnt allow values greater than 10.
if (value > 10) {
throw new IllegalArgumentException();
}
this.value = value;
|
public void | someMethod(oreilly.hcj.review.FriendAccess obj)If the comparison instance and this instance are both 5 then set the compare
object's value to 25.
if ((obj.value == 5) && (this.value == 5)) {
obj.value = 25; // <= Ouch, this works and bypasses the setter.
}
|