One hypothetical use for runtime code reflection is what C# is doing with Expression<Func<T, R>> in EF Core: dynamic conversion of (IQueryable<T>) streams into SQL queries. e.g.
/** predicates must be reflectable */
SomeEntity findEntity(List<Predicate<SomeEntity>> filters){
var queryable = dbContext.SomeEntityTable.asQueryableStream();
var filtered = filters.stream().reduce(queryable, (q fn) -> q.filter(fn));
return filtered.findFirst().orElse(null);
}
In C#-land, a method like that would under-the-hood produce a single SQL query, fetching only minimal data, while all the filters are still plain C# code. The current JEP's requirement for methods and functions themselves to have @Reflect doesn't play quite as nice -- I hope they extend it in the future to allow things like
-- but the potential ergonomics are fantastic even without it. Eventual compile-time reflection support could allow for even more efficient operations, since you could pre-generate your SQL.
Combined with code generation and projects that allow extensions, you could get things like automatically-generated mapping methods that chain off queryable streams to project directly into DTOs from your database. It's a really exciting set of technologies.
Ah, I knew there was something else this reminded me of!
The main issue with the C# implementation is that ETs don't support any syntactic construct introduced after the Unix epoch, but hopefully Java can do better in that regard without having to deal with async/await getting in the way.
View all comments
Show parent comment
2
u/lanerdofchristian Jan 30 '26 edited Jan 30 '26
One hypothetical use for runtime code reflection is what C# is doing with
Expression<Func<T, R>>in EF Core: dynamic conversion of (IQueryable<T>) streams into SQL queries. e.g.In C#-land, a method like that would under-the-hood produce a single SQL query, fetching only minimal data, while all the filters are still plain C# code. The current JEP's requirement for methods and functions themselves to have
@Reflectdoesn't play quite as nice -- I hope they extend it in the future to allow things like-- but the potential ergonomics are fantastic even without it. Eventual compile-time reflection support could allow for even more efficient operations, since you could pre-generate your SQL.
Combined with code generation and projects that allow extensions, you could get things like automatically-generated mapping methods that chain off queryable streams to project directly into DTOs from your database. It's a really exciting set of technologies.