Java Magazine, Sept/Oct 2018
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2018 24 the leading edge Context context Context create Value result context eval js 42 assert result asInt 42 Value is how languages communicate with each other Any Java object can be converted to a Value with the Value asValue Object value method call and the Value can be converted to its Java counterpart with Value as Class T targetType The exact description of the conversion process is outside the scope of this article but the API always tries to do the sensible thing it converts numbers to numbers strings to Strings values that can be executed to functional interfaces collections to collections and so on For example all of the following expressions are true context eval js foobar as String class equals foobar context eval js foo bar as Map class get foo equals bar @ FunctionalInterface interface IntFunction int f int value context eval js function a a as IntFunction class f 42 42 Armed with the Context and the Value you can pass data between the components written in diferent languages However a modern application will probably hide the details of the polyglot implementation of its components behind some abstraction For example this demo application is a Spring Boot web app that uses R to plot CPU utilization data as an SVG image In the app the GraalVM polyglot context is defined as a Spring @ Bean @ Bean public Context getGraalVMContext return Context newBuilder allowAllAccess true build
You must have JavaScript enabled to view digital editions.