title: Better alternative to using Void for optional argument
body: <p>I have an interface specifying method that takes a generic type as input which is used to create a URL. </p>
  
  <pre><code>interface UrlGenerator&lt;T&gt; {
  
      String prepareUrl( T input );
  
  }
  </code></pre>
  
  <p>There is one implementation that doesn't need the parameter. It uses Void for generic type T.</p>
  
  <pre><code>class StaticUrlGenerator implements UrlGenerator&lt;Void&gt; {
  
      private final String url;
  
      public StaticUrlGenerator( String url ) {
          this.url = url;
      }
  
      @Override
      public String prepareUrl( Void nothing ) {
          return url;
      }
  
  }
  </code></pre>
  
  <p>The StaticUrlGenerator is awkward to use, as it requires null as an argument to the <code>prepareUrl</code> method. </p>
  
  <p>I could lose the <code>input</code> parameter:</p>
  
  <pre><code>interface UrlGenerator&lt;T&gt; {
  
      String prepareUrl( T input );
  
  }
  </code></pre>
  
  <p>Now I have to pass the required input to the implementing class in other way (in constructor). This way I lose the stateless nature of the class, I have to recreate it with different constructor arguments every time I want to change the input.</p>
  
  <pre><code>class SchedulePageUrlGenerator implements UrlGenerator {
  
      public static final String QUERY_STRING_BASE = "?from=";
  
      private final String showingBaseUrl;
      private final LocalDate date;
  
      public SchedulePageUrlGenerator( String showingBaseUrl, LocalDate date ) {
          this.showingBaseUrl = showingBaseUrl;
          this.date = date;
      }
  
      @Override
      public String prepareUrl() {
          DateTimeFormatter fmt = DateTimeFormat.forPattern( "yyyy-MM-dd" );
          String dateStr = fmt.print( date );
          return showingBaseUrl + QUERY_STRING_BASE + dateStr;
      }
  
  }
  </code></pre>
  
  <p>I think there must be something fundamentally wrong with my design.</p>