Created
June 27, 2018 08:49
-
-
Save pmlopes/6021d34f920f8e24b391b38fcf1987e9 to your computer and use it in GitHub Desktop.
Graal JS Overload issue
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
@FunctionalInterface | |
public interface Handler<T> { | |
void handle(T value); | |
} |
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
import org.graalvm.polyglot.Context; | |
public class Main { | |
static String script = | |
"const Tuple = Java.type('Tuple');\n" + | |
"const Pool = Java.type('Pool');\n" + | |
"\n" + | |
"let pool = new Pool();\n" + | |
"\n" + | |
"pool.prepare('SELECT ...', new Tuple(), res => {\n" + | |
" print(res);\n" + | |
"});"; | |
public static void main(String[] args) { | |
Context polyglot = Context | |
.newBuilder("js") | |
.allowAllAccess(true) | |
.build(); | |
polyglot.eval("js", script); | |
} | |
} |
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
An exception occured while executing the Java class. TypeError: INVOKE on JavaObject[bugs.Pool@39eb534c (bugs.Pool)] failed due to: java.lang.IllegalArgumentException: Multiple applicable overloads found for method name prepare (candidates: [Method[public void bugs.Pool.prepare(java.lang.String,bugs.Tuple,bugs.Handler)], Method[public void bugs.Pool.prepare(java.lang.String,java.util.stream.Collector,bugs.Handler)]], arguments: [SELECT ... (String), JavaObject[bugs.Tuple@8b41341 (bugs.Tuple)] (JavaObject), DynamicObject<JSFunction>@daa14ca (DynamicObjectBasic)]) |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>io.silver</groupId> | |
<artifactId>bugs</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>org.graalvm</groupId> | |
<artifactId>graal-sdk</artifactId> | |
<version>1.0.0-rc2</version> | |
<scope>provided</scope> | |
<optional>true</optional> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.1</version> | |
<configuration> | |
<source>1.8</source> | |
<target>1.8</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.codehaus.mojo</groupId> | |
<artifactId>exec-maven-plugin</artifactId> | |
<version>1.6.0</version> | |
<executions> | |
<execution> | |
<goals> | |
<goal>java</goal> | |
</goals> | |
</execution> | |
</executions> | |
<configuration> | |
<mainClass>Main</mainClass> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
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
import java.util.stream.Collector; | |
public class Pool { | |
public void prepare(String query, Tuple tuple, Handler<String> handler) { | |
handler.handle("OK"); | |
} | |
public void prepare(String query, Collector collector, Handler<String> handler) { | |
handler.handle("OK"); | |
} | |
} |
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
public class Tuple { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment