Il problema qui e' il boxing/unboxing under the hood, che non e' "visible"
in quel pezzetto di codice a meno che tu non estragga quelle due
variabili.  Quando vedi che sono *Integer* lo sai che un "=" e'
una minchiata a prescindere dal pattern utilizzato a generare l'istanza.

La cache e' comunque un problema perche i test sono verdissimi a meno che
tu non vada con un valore al di fuori della cache. Quel codice era infatti
testato e con 100% coverage :)

Ciaps!

--
Bruno Bossola
CTO - meterian.io
Scan your website now! <https://www.meterian.com/webscanner.html>
Scan your project now! <https://www.meterian.com/projectscanner.html>


On Tue, 4 Aug 2020 at 16:25, Andrea Ligios [email protected]
[it-torino-java-jug] <[email protected]> wrote:

>
>
> Ciao,
> è il mitico Flyweight pattern :) me lo ricordavo dalla famosa Q&A di
> BalusC sulle implementazioni pratiche dei GoF
> <https://stackoverflow.com/a/2707195/1654265>.
>
> Occhio perché è implementato in parecchi altri posti:
>
>> Flyweight <http://en.wikipedia.org/wiki/Flyweight_pattern> (recognizeable
>> by creational methods returning a cached instance, a bit the "multiton"
>> idea)
>>
>>    - java.lang.Integer#valueOf(int)
>>    
>> <http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#valueOf-int->
>>    (also on Boolean
>>    
>> <http://docs.oracle.com/javase/8/docs/api/java/lang/Boolean.html#valueOf-boolean->,
>>    Byte
>>    
>> <http://docs.oracle.com/javase/8/docs/api/java/lang/Byte.html#valueOf-byte->,
>>    Character
>>    
>> <http://docs.oracle.com/javase/8/docs/api/java/lang/Character.html#valueOf-char->,
>>    Short
>>    
>> <http://docs.oracle.com/javase/8/docs/api/java/lang/Short.html#valueOf-short->,
>>    Long
>>    
>> <http://docs.oracle.com/javase/8/docs/api/java/lang/Long.html#valueOf-long->
>>    and BigDecimal
>>    
>> <https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#valueOf-long-int->
>>    )
>>
>>
> Un saluto
>
> Andrea
>
> Il giorno mar 4 ago 2020 alle ore 17:11 Carlo Pellegrini
> [email protected] [it-torino-java-jug] <
> [email protected]> ha scritto:
>
>>
>>
>> Ciao Bruno!
>>    Purtroppo è capitato anche a me qualche tempo fa...
>> La IntegerCache è comoda, ma nasconde questi errori subdoli, in più può
>> cambiare a runtime con -Djava.lang.Integer.IntegerCache.high=<size>.
>>
>> 
>

Reply via email to