What is a final field? #javalanguage #javacoding #javatips #javacodinginterview

preview_player
Показать описание
Cracking the #Java #Coding #Interview - Question 231: What is a final field?
Рекомендации по теме
Комментарии
Автор

I didn't know about the visibility from other threads. Nice!

KevinSheppard
Автор

Static final doesn't need to have an initializer, you can set them in static block.

gudenau
Автор

If a field is final, I believe there was different Jvm optimization going on behind the scenes. I’d like to have a video about that 🙃

Ambusher
Автор

If you let your object escape from the constructor, like sending a reference using a queue to another thread, the other thread reading the final field may see a null/0/false uninitialized value and IT MAY SEE LIKE THAT, uninitialized much later, when the field got the value in the constructor, because it knows it is final, no need to update the cached local value.

It is not a made up example. It was bug tricky to find in commercial code. Real life. Never allow ‘this’ to escape from the constructor. Simplest: if you see ‘this’ passed as argumet you may be in trouble.

PeterVerhas
Автор

next james bond should have that voice a elegance, he'd call java bond

haroldpepete
Автор

Short answer is always the smart-ass answer 😂

apinakapinastorba
Автор

java is the best language for desktop apps

rezah
welcome to shbcf.ru