vendredi 13 novembre 2015

Java: Empty constructor accepting a parameter

I try to understand the lazy initialization pattern described on Wikipedia. There is a constructor accepting a FRUIT_TYPE type argument. While initializing, the hash map is being checked whether or not it already has a given fruit type and if not the constructor is used to create a fruit out of the given type. The fruit is then being put in the map. I copy-pasted the example and it worked fine. But how the fruit is being created without the (imo)necessary field for setting it to the given param in the constructor, e. g.

private FRUIT_TYPE fruitType;
private Fruit(FRUIT_TYPE type){this.fruitType = type}

What am I missing?

Aucun commentaire:

Enregistrer un commentaire