je tam problem v naruseni vlastnosti symetrie, ktora je jedna zo
styroch, ktore musi equals() splnat. Vid napr.
http://www.geocities.com/technofundo/tech/java/equalhash.html
"instanceof" moze robit problem. Jedine v pripade "final" tried je to v
poriadku. Mozno je to az prilis nad ramec povodnej otazky, ale pre
uplnost ked uz sa tu spominaju metody equals() a hashCode().
Inak odporucam Kamzikovi precitat si uz niekym dnes spominanu knihu:
Josh Bloch: Effective Java
i.
Kamzik-II wrote:
> Tak jsem si to vsechno vyzkousel,
> a implementace by mela tim padem vypadat asi takhle:
>
> class CustomPermission
> {
>
> public CustomPermission ( String name )
> {
>
> super ( name );
>
> }
>
> ...
>
> public int hashCode ()
> {
>
> return this.getName ().hashCode ();
>
> }
>
> public boolean equals ( Object object )
> {
>
> if ( object instanceof CustomPermission )
> {
>
> CustomPermission cp = (CustomPermission) object;
> if ( ( cp.getName == this.getName () ) && cp.getActions () ==
> this.getActions () )
> return true;
>
>
> }
> return false;
>
> }
>
> }
>
> nemam tam nejakou salamounskou chybu?