Telegram Group & Telegram Channel
equals, hashCode

Эти два метода придуманы для использования в Java Collections Framework и связаны общим контрактом, для соблюдения которого переопределять их необходимо вместе. Методы обязательно нужно переопределить чтобы эффективно использовать экземпляры как ключи в HashMap или HashSet. HashMap работает тем эффективнее, чем «лучше» распределение хэшей.

Контракт:
1. Если объекты equals, у них должны быть одинаковые hashCode (не обязательно наоборот – коллизии допустимы!)
2. equals должен быть отношением эквивалентности
3. Ничто не может быть equals(null)
4. equals и hashCode должны возвращать одни и те же значения для одного и того же объекта при каждом последующем вызове, даже если состояние объекта изменилось. Это делает реализацию для изменяемых (mutable) объектов крайне сложной.

По умолчанию equals сравнивает на ==. С умолчательным hashCode дела обстоят интереснее: он зависит от реализации JVM, и может быть неожиданным. Например в OpenJDK 7 это случайное число.

Подробная инструкция по переопределению этих методов описана в Effective Java Item 9 (больше деталей о волшебном числе 31 здесь).

#МетодыObject



group-telegram.com/JavaSobes/379
Create:
Last Update:

equals, hashCode

Эти два метода придуманы для использования в Java Collections Framework и связаны общим контрактом, для соблюдения которого переопределять их необходимо вместе. Методы обязательно нужно переопределить чтобы эффективно использовать экземпляры как ключи в HashMap или HashSet. HashMap работает тем эффективнее, чем «лучше» распределение хэшей.

Контракт:
1. Если объекты equals, у них должны быть одинаковые hashCode (не обязательно наоборот – коллизии допустимы!)
2. equals должен быть отношением эквивалентности
3. Ничто не может быть equals(null)
4. equals и hashCode должны возвращать одни и те же значения для одного и того же объекта при каждом последующем вызове, даже если состояние объекта изменилось. Это делает реализацию для изменяемых (mutable) объектов крайне сложной.

По умолчанию equals сравнивает на ==. С умолчательным hashCode дела обстоят интереснее: он зависит от реализации JVM, и может быть неожиданным. Например в OpenJDK 7 это случайное число.

Подробная инструкция по переопределению этих методов описана в Effective Java Item 9 (больше деталей о волшебном числе 31 здесь).

#МетодыObject

BY Java Interview Review


Warning: Undefined variable $i in /var/www/group-telegram/post.php on line 260

Share with your friend now:
group-telegram.com/JavaSobes/379

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

Telegram was founded in 2013 by two Russian brothers, Nikolai and Pavel Durov. Telegram has gained a reputation as the “secure” communications app in the post-Soviet states, but whenever you make choices about your digital security, it’s important to start by asking yourself, “What exactly am I securing? And who am I securing it from?” These questions should inform your decisions about whether you are using the right tool or platform for your digital security needs. Telegram is certainly not the most secure messaging app on the market right now. Its security model requires users to place a great deal of trust in Telegram’s ability to protect user data. For some users, this may be good enough for now. For others, it may be wiser to move to a different platform for certain kinds of high-risk communications. On February 27th, Durov posted that Channels were becoming a source of unverified information and that the company lacks the ability to check on their veracity. He urged users to be mistrustful of the things shared on Channels, and initially threatened to block the feature in the countries involved for the length of the war, saying that he didn’t want Telegram to be used to aggravate conflict or incite ethnic hatred. He did, however, walk back this plan when it became clear that they had also become a vital communications tool for Ukrainian officials and citizens to help coordinate their resistance and evacuations. Update March 8, 2022: EFF has clarified that Channels and Groups are not fully encrypted, end-to-end, updated our post to link to Telegram’s FAQ for Cloud and Secret chats, updated to clarify that auto-delete is available for group and channel admins, and added some additional links. In the past, it was noticed that through bulk SMSes, investors were induced to invest in or purchase the stocks of certain listed companies.
from de


Telegram Java Interview Review
FROM American