title: Multiple optional arguments in constructor in Java - exponential number of constructors
body: <p>This is something I've encountered a few times and haven't been able to find a satisfying answer yet. This seems pretty stupid, but after googling this for a while I couldn't come up with something good.</p>
  
  <p>Let's say I have a class with 20 instance variables, each of which is optional (will be initialized or not).</p>
  
  <p>Now I want my constructor(s) to handle all the cases, in case of a few instance variables it's fine and I can just create constructors with different signatures, but here I have 20, so I would need <strong>2^20=1,048,576</strong> constructors to handle all the cases ! That seems ... not very optimal, don't you agree?</p>
  
  <p>So since with this brute force approach I basically have to construct 2^n constructors, where n is the number of instance variables, I want to find a better way to do it.</p>
  
  <p>I've seen a couple solutions for this problem, but I believe they all on assumptions on the data, but in my case each of these variables can be initialized or not at random, I have no way of knowing that before initialization.</p>
  
  <p>I'm looking for some design patterns or ideas that I could apply to make my code a bit more ... maintainable (no don't worry I didn't create 1M+ constructors :)</p>
  
  <p>Thanks.</p>