Java Challengers #13 - Wrappers, cache, equals vs ==

preview_player
Показать описание
Learn the tricks of a wrapper class, the difference between equals and '==' with Java by having fun guessing on this Java Challenge!

Get the code of the Java Challengers and run your own tests:

Рекомендации по теме
Комментарии
Автор

Subscribe! This is exactly what I'm looking for! This is what fricking years of university were unable to teach students who had to look things up on their own.

danstoian
Автор

The subject is a little tricky, could you please give me a hint:
ArrayList<Integer> list = new ArrayList<>();
list.add(14);
Integer a = list.get(0);
Integer b = 14;

a==b is true.


Integer c = new Integer(14);

Integer d = 14;
c==d is false.
Why it is differents, normally we should get true in both cases.

momedalhouma
Автор

thanks for the nice challenge, unfotunatly they don't ask questions ^-^; So i wil do
1- what are the other wrapper class that have the same cache behaviour as the Integer class, for example if we had double in place of Integer, do we get the same behaviuour.
2- you mentioned in this video that almost we have the same behaviour for the class String, what did you mean by that, did you mean the String pool.
3- have you done some challenges on the String class.
big thanks

momedalhouma