Skip to content

Commit 7c15813

Browse files
authored
Add constructor de-ambiguation info to docs page (#3925)
1 parent 9334cad commit 7c15813

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/content/Modpacks/Other-Topics/Ambiguous-Methods.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Ambiguous Methods
33
---
44

5+
## Ambiguous Methods
56
Sometimes in KJS, you run into ambiguous methods when calling functions.
67
This happens when there's multiple overloads (e.g. methods with the same name but different types) and KubeJS isn't sure which function to call with your arguments.
78

@@ -52,5 +53,48 @@ GTCEuStartupEvents.registry('gtceu:machine', event => {
5253
```
5354

5455
Because of the way javascript indexing works, `.foo` and `["foo"]` are the same thing, so you can just keep chaning your functions afterward, since it's just a "normal" builder method, just called in a more specific way.
56+
57+
## Ambiguous Constructors
58+
This same problem can occur when trying to call a constructor.
59+
For example, when you do
60+
```js
61+
GTCEuStartupEvents.registry("gtceu:recipe_type", event => {
62+
event.create("unboxinator")
63+
.setProgressBar(
64+
new ResourceTexture("kubejs:textures/gui/progress_bar/progress_bar_stone_oreifier.png"),
65+
FillDirection.LEFT_TO_RIGHT
66+
)
67+
// Rest of the recipe type
68+
})
69+
```
70+
You'd get the following error:
71+
```
72+
dev.latvian.mods.rhino.EvaluatorException: The choice of Java constructor com.lowdragmc.lowdraglib.gui.texture.ResourceTexture matching JavaScript argument types (string) is ambiguous; candidate constructors are:
73+
ResourceTexture(net.minecraft.resources.ResourceLocation)
74+
ResourceTexture(java.lang.String) (startup_scripts:example.js#17)
75+
```
76+
77+
You would want to select one of the two, and this can be done in the following way:
78+
```js
79+
GTCEuStartupEvents.registry("gtceu:recipe_type", event => {
80+
event.create("unboxinator")
81+
.setProgressBar(
82+
ResourceTexture["(java.lang.String)"]("kubejs:textures/gui/progress_bar/progress_bar_stone_oreifier.png"),
83+
FillDirection.LEFT_TO_RIGHT
84+
)
85+
// Rest of the recipe type
86+
})
87+
```
88+
or
89+
```js
90+
GTCEuStartupEvents.registry("gtceu:recipe_type", event => {
91+
event.create("unboxinator")
92+
.setProgressBar(
93+
ResourceTexture["(net.minecraft.resources.ResourceLocation)"](new ResourceLocation("kubejs:textures/gui/progress_bar/progress_bar_stone_oreifier.png")),
94+
FillDirection.LEFT_TO_RIGHT
95+
)
96+
// Rest of the recipe type
97+
})
98+
```
5599
!!! Note
56100
Generics don't exist in compiled code, so e.g. a call to `memoize(Supplier<T> delegate)` would turn into `["memoize(Supplier)"](...)`

0 commit comments

Comments
 (0)