temperlang / temper

3 stars 0 forks source link

Java callback types sometimes fail across libraries #135

Closed tjpalmer closed 6 months ago

tjpalmer commented 6 months ago

This definitely applies some to use of temper-core, but I think it applies elsewhere. We need to use the SAM types from the library that consumes the SAM object rather than local SAM types. This matters especially for multi-parameter function types, since java.util.function often helps less at 2+ parameters. For example we have this function in Core.java:

    public static <K, V, T> List<T> mappedToListWith(Map<K, V> map, BiFunction<K, V, T> fn) { ... }

But we might try to use it like this in generated code:

                IntStringInt fn__457 = (k__35, v__36) -> k__35;
                Core.mappedToListWith(messages__14, fn__457);
tjpalmer commented 6 months ago

I think the easiest solution might be always to pass as method references. Like instead of this:

                IntStringInt fn__457 = (k__35, v__36) -> k__35;
                Core.mappedToListWith(messages__14, fn__457);

Say this:

                IntStringInt fn__457 = (k__35, v__36) -> k__35;
                Core.mappedToListWith(messages__14, fn__457::apply);

Simplest is to do that in all cases. Next simplest is in all cases when calling methods (including property assignment) outside the current library.