Duplicate :
|
A DESCRIPTION OF THE REQUEST : When we program in Java and Other language, such as Groovy and JavaScript, we have to write \' , \n, \" and + many times. For example, /* Without treble quotation marks supported, Java program embeded with Groovy code */ GroovyShell shell = new GroovyShell(binding); Object value = shell.evaluate( "println 'Hello World!';\n" + "x = 123;\n" + "for (i in 0..9) {\n" + " x += i;\n" + " println x;\n" + "}\n" + "return foo = foo * 10;" ); If Java supports treble quotation marks, we can program like following code. The Java code become much more concise than before. /* With treble quotation marks supported, Java program embeded with Groovy code */ GroovyShell shell = new GroovyShell(binding); Object value = shell.evaluate( """ println 'Hello World!'; x = 123; for (i in 0..9) { x += i; println x; } return foo = foo * 10; """ ); JUSTIFICATION : The enhancement will make Java more concise and more readable. Especially, JDK6.0 will support JavaScript code embeded in Java code, the enhancement will play an important role in Java programming in future. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - /* With treble quotation marks supported, Java program embeded with Groovy code */ GroovyShell shell = new GroovyShell(binding); Object value = shell.evaluate( """ println 'Hello World!'; x = 123; for (i in 0..9) { x += i; println x; } return foo = foo * 10; """ ); ACTUAL - /* Without treble quotation marks supported, Java program embeded with Groovy code */ GroovyShell shell = new GroovyShell(binding); Object value = shell.evaluate( "println 'Hello World!';\n" + "x = 123;\n" + "for (i in 0..9) {\n" + " x += i;\n" + " println x;\n" + "}\n" + "return foo = foo * 10;" ); ---------- BEGIN SOURCE ---------- // EmbedTest .java import groovy.lang.Binding; import groovy.lang.GroovyShell; import org.codehaus.groovy.control.CompilationFailedException; public class EmbedTest { public static void main(String[] args) { Binding binding = new Binding(); binding.setVariable("foo", new Integer(2)); GroovyShell shell = new GroovyShell(binding); try { Object value = shell.evaluate( "println 'Hello World!';\n" + "x = 123;\n" + "for (i in 0..9) {\n" + " x += i;\n" + " println x;\n" + "}\n" + "return foo = foo * 10;" ); } catch (CompilationFailedException e) { e.printStackTrace(); } } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Not found :-(