[Swift-devel] Problems calling java.lang.String format method

Michael Wilde wilde at anl.gov
Thu Oct 23 18:45:37 CDT 2014


Im trying to call .format( ) from java.lang.String, from the Swift 
function java( ).

Is it possible to call Java functions whose args are typed Object? (such 
as .format)

 From this code:

// String result = String.format("%4d", i * j);

string result = java("java.lang.String","format","%4d",9876);
tracef("result=%s\n", result);

I get the error below, which suggests that the java( ) function can only 
find a fairly narrow range of methods whose signatures exactly match the 
signature that the Swift args are directly mapped to.

T$ swift s.swift
Swift trunk git-rev: 870bd2114e6bdcab18278d44208defbf7c077fdc 
heads/master 6143
RunID: run013
Progress: Thu, 23 Oct 2014 19:35:52-0400
java.lang.NoSuchMethodException: 
java.lang.String.format(java.lang.String, int)
     at java.lang.Class.getMethod(Class.java:1665)
     at org.griphyn.vdl.karajan.lib.swiftscript.Java.getMethod(Java.java:88)
     at org.griphyn.vdl.karajan.lib.swiftscript.Java.function(Java.java:56)
     at 
org.griphyn.vdl.karajan.lib.SwiftFunction.runBody(SwiftFunction.java:77)
     at 
org.globus.cog.karajan.compiled.nodes.InternalFunction.run(InternalFunction.java:175)
     at 
org.globus.cog.karajan.compiled.nodes.CompoundNode.runChild(CompoundNode.java:110)
     at 
org.globus.cog.karajan.compiled.nodes.InternalFunction.run(InternalFunction.java:165)
     at 
org.globus.cog.karajan.compiled.nodes.CompoundNode.runChild(CompoundNode.java:110)
     at 
org.globus.cog.karajan.compiled.nodes.Sequential.run(Sequential.java:41)
     at 
org.globus.cog.karajan.compiled.nodes.CompoundNode.runChild(CompoundNode.java:110)
     at 
org.globus.cog.karajan.compiled.nodes.UParallel$1.run(UParallel.java:91)
     at k.thr.LWThread.run(LWThread.java:247)
     at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
     at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
     at java.lang.Thread.run(Thread.java:744)
dir=/lustre/atlas2/mat049/proj-shared/wildemj/bes-diffuse-demo-2014/swift-discus/swiftk

Execution failed:
@java(): Error attempting to use: java.lang.String
     swiftscript:java @ s, line: 51

Or better yet: is there already an undocumented sprintf( ) function 
(which is what Im trying to do here).

Thanks,

- Mike



-- 
Michael Wilde
Mathematics and Computer Science          Computation Institute
Argonne National Laboratory               The University of Chicago




More information about the Swift-devel mailing list