I am trying to use the lambda expression to simplify the below code snipped. A detailed info can be found here: Could not serialize object cause of HibernateProxy.
public class HibernateProxyTypeAdapter extends TypeAdapter<HibernateProxy> {
public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
@Override
@SuppressWarnings("unchecked")
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
return (HibernateProxy.class.isAssignableFrom(type.getRawType())
? (TypeAdapter<T>) new HibernateProxyTypeAdapter(gson)
: null);
}
};
...
...
...
}
I changed the code to this:
public static final TypeAdapterFactory FACTORY = (gson, type) -> HibernateProxy.class.isAssignableFrom(type.getRawType())
? (TypeAdapter<T>) new HibernateProxyTypeAdapter(gson)
: null;
But I am getting an error in Eclispe
: Illegal lambda expression: Method create of type TypeAdapterFactory is generic
I also tried this one but throws me the same error.
public static final TypeAdapterFactory FACTORY = (gson, type) -> HibernateProxy.class.isAssignableFrom(type.getRawType())
? (TypeAdapter<Hibernate>) new HibernateProxyTypeAdapter(gson)
: null;
Is it possible to use the lambda expression in this situation? How should I modify my code?