[resteasy-dev] Lambda question
Rebecca Searls
rsearls at redhat.com
Mon Apr 3 14:07:58 EDT 2017
This may be the cause as discussed here
http://stackoverflow.com/questions/22588518/lambda-expression-and-generic-method
You can't use a lambda expression for a functional interface, if the method in the functional
interface has type parameters. JSE spec section:
http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27.3
----- Original Message -----
> From: "Ron Sigal" <rsigal at redhat.com>
> To: resteasy-dev at lists.jboss.org
> Sent: Monday, April 3, 2017 1:11:38 PM
> Subject: [resteasy-dev] Lambda question
>
>
>
> This question arises in https://issues.jboss.org/browse/RESTEASY-1209
> "org.jboss.resteasy.util.Types#getActualTypeArgumentsOfAnInterface not
> working for lambda's." The reporter wants to do this:
>
>
>
>
>
>
>
> ResteasyProviderFactory factory = new ResteasyProviderFactory();
> factory.register((ContextResolver<String>) type -> "foo bar");
>
>
>
> but it doesn't work. I find that if I do this:
>
>
>
> ContextResolver<String> resolver1 = new ContextResolver<String>() {
>
> @Override
> public String getContext(Class<?> type)
> {
> return null;
> }
> };
> for (Type type : resolver1.getClass().getGenericInterfaces())
> {
> System.out.println(type);
> }
> I get
>
>
>
> javax.ws.rs.ext.ContextResolver<java.lang.String>
> but if I do
>
>
>
> ContextResolver<String> resolver2 = type -> "foo";
> for (Type type : resolver2.getClass().getGenericInterfaces())
> {
> System.out.println(type);
> }
> I get
>
>
>
> interface javax.ws.rs.ext.ContextResolver
> Same with
>
>
>
> ContextResolver<String> resolver2 = ((ContextResolver<String>)type -> "foo");
> So, it seems that, for lambdas, Java doesn't keep the implementation type and
> value of the type variable at run time. Does anyone have any ideas or
> tricks?
>
> Thanks,
> Ron
>
>
>
>
> --
> My company's smarter than your company (unless you work for Red Hat)
>
> _______________________________________________
> resteasy-dev mailing list
> resteasy-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/resteasy-dev
>
More information about the resteasy-dev
mailing list