I am not sure can we write the generic method as a function programming using Java 8 lamda expression as below
Generic method
public <T> MongoCollection<T> getCollection(String collectionName, Class<T> typeParameterClass) {
return mongoClient
.getDatabase(mongodbConfiguration.getDatabase())
.getCollection(collectionName, typeParameterClass);
}
I want to convert this generic method to generic functional lamda expression as below
public BiFunction<String, Class<T>, T> getCollection = (collectionName, typeParameterClass) -> {
return mongoClient
.getDatabase(mongodbConfiguration.getDatabase())
.getCollection(collectionName, typeParameterClass);
};
From the above code I have an error on type T and typeParameterClass
Update 1
While implementing the method suggested by @Clashsoft the second argumenent is Class<Object> instead of Class<T>
repository.getCollectionFactory().apply("", Category.class);


BiFunction<String, Class<T>, MongoCollection<T>>(though I don't think that'll work either), as the return type isMongoCollection<T>, and notT.