title: Spring can't determine generic types when lambda expression is used instead of anonymous inner class
body: <p>I'm playing around with Spring's <code>ConversionService</code>, adding a simple converter to convert a <code>ZonedDateTime</code> (Java 8) to <code>String</code>:</p>
  
  <pre><code>@Bean
  public ConversionServiceFactoryBean conversionServiceFactoryBean() {
      ConversionServiceFactoryBean conversionServiceFactoryBean =
          new ConversionServiceFactoryBean();
  
      Converter&lt;ZonedDateTime, String&gt; dateTimeConverter =
          new Converter&lt;ZonedDateTime, String&gt;() {
              @Override
              public String convert(ZonedDateTime source) {
                  return source.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
              }
          };
  
      conversionServiceFactoryBean.setConverters(
          new HashSet&lt;&gt;(Arrays.asList(dateTimeConverter)));
      return conversionServiceFactoryBean;
  }
  </code></pre>
  
  <p>This works fine. But my IDE (IntelliJ) suggests replacing the anonymous inner class with a lambda expression:</p>
  
  <pre><code>Converter&lt;ZonedDateTime, String&gt; dateTimeConverter =
      source -&gt; source.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
  </code></pre>
  
  <p>If I do that, then it doesn't work anymore, I get an error about Spring not being able to determine the generic types:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Unable to the determine sourceType &lt;S&gt; and targetType &lt;T&gt; which your Converter&lt;S, T&gt; converts between; declare these generic types.
      at org.springframework.util.Assert.notNull(Assert.java:112)
      at org.springframework.core.convert.support.GenericConversionService.addConverter(GenericConversionService.java:100)
      at org.springframework.core.convert.support.ConversionServiceFactory.registerConverters(ConversionServiceFactory.java:50)
      at org.springframework.context.support.ConversionServiceFactoryBean.afterPropertiesSet(ConversionServiceFactoryBean.java:70)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
  </code></pre>
  
  <p>The <code>Class</code> object that represents the lambda expression is apparently different enough from the <code>Class</code> for the anonymous inner class that Spring can't determine the generic types anymore. How does Java 8 do this exactly with lambda expressions? Is this a bug in Spring that is fixable or does Java 8 just not provide the necessary information?</p>
  
  <p>I'm using Spring version 4.1.0.RELEASE and Java 8 update 20.</p>