Last active
August 29, 2015 14:07
-
-
Save walterhiggins/8de7a93e8b57e62aa16d to your computer and use it in GitHub Desktop.
Trying to call an overloaded constructor with vararg parameters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cmRecipe = Packages.net.canarymod.api.recipes.CraftingRecipe; | |
var cmRecipeRow = Packages.net.canarymod.api.recipes.RecipeRow; | |
// see https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/api/inventory/recipes/CraftingRecipe.html | |
var rows = [ | |
new cmRecipeRow("ESW", [ enderPearl, stick, string]), | |
new cmRecipeRow("SEW", [ stick, enderPearl, string]), | |
new cmRecipeRow("ESW", [ enderPearl, stick, string]) | |
]; | |
var signature = "(net.canarymod.api.inventory.Item, net.canarymod.api.inventory.recipes.RecipeRow[])"; | |
var enderBowRecipe = new cmRecipe[signature]( enderBow, rows); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have several options (sorry, I'll be typing these off the top of my head, not trying them out myself, so minor errors are possible).
1. Explicit constructor overload selection
This is something that will only work in Java 8u40 (it's already available in the early access builds). However, you'd use the explicit signature as part of the type name on the package, and not as a property of the constructor object itself:
(Notice, by the way, that you can use unqualified type names for the signature as Nashorn is smart enough to know that you're selecting among a finite number of overloads and can figure out what you meant. You would only need to use qualified type names in case two overloads could only be distinguished by parameter types in the same position that have the same unqualified name but different packages. Which is practically (hopefully) never.)
2. Coerce the array argument into explicit Java array type
This solution is available since Nashorn was first released in Java 8; you just use
Java.to
with a specific Java array type:Hope this helps,
Attila.