Adding providers to `DataGenerator` via lambda is ambiguous
Minecraft Version: 1.20.4 NeoForge Version: 20.4.232 Logs: https://gist.github.com/rlnt/2866adea220d3f8e80aa6771a8357569
Steps to Reproduce:
- Create a class that extends the NeoForge
LanguageProvider - Create a method where you have the
GatherDataEventas parameter - Get the generator from the event via
event.getGenerator() - Call the
addProvidermethod on the generator that uses theDataProvider.Factory<T>
Description of issue: You can't compile the code because the call is ambiguous.
Edit: code snippets because the log is a bit odd
public final class LazierLang extends LanguageProvider {
LazierLang(PackOutput output) {
super(output, BuildConfig.MOD_ID, "en_us");
}
@Override
protected void addTranslations() {
}
}
public final class DataGeneration {
private DataGeneration() {}
public static void init(GatherDataEvent event) {
DataGenerator generator = event.getGenerator();
generator.addProvider(event.includeClient(), LazierLang::new);
}
}
Don't you need a new operator to create an instance of your data provider?
He means:
generator.addProvider(true, Provider::new)
javac complains that this is ambiguous
Is this just poor method resolution on javac's side? The two method signatures are
public <T extends DataProvider> T addProvider(boolean run, DataProvider.Factory<T> factory);
public <T extends DataProvider> T addProvider(boolean run, T provider);
There's no question that T::new should not bind to T
I think the problem is both take the same parameter (constructor and the datagen run method), just differ in return types.
I assumed that it may be ambiguous due to T referring to the DataProvider interface which only has one method and is then interpreted as a functional interface as well. The @FunctionalInterface annotation in Java is optional and just an indicator.