Let's say I have a simple interface:
interface IGroupBy {
String getGroupById();
}
Say I have a list of this:
List<IGroupBy> v = List.of();
But this means that the list has to implement that interface by name. But what if I am willing to accept any object that had a method that returns a string with that name?
Is there a way to get structural typing in Java using generics somehow?
List<T> v = List.of();
and then tell the Java compiler about T? Something like:
<T hasInterface:IGroupBy>
I suppose one way to get part of the way there is using generics like this:
interface IGroupBy<T> {
T getGroupById();
}
the remaining part is the method name. But that still means you have to reference the same exact interface by name/package.