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

Justin M Wozniak wozniak at mcs.anl.gov
Thu Oct 23 19:23:23 CDT 2014


Yes, there is a sprintf().  There are a few uses in the test suite.  I'm 
not sure what to do about methods on Object but we could discuss on the 
call tomorrow.

On 10/23/2014 06:45 PM, Michael Wilde wrote:
> 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
>
>
>


-- 
Justin M Wozniak




More information about the Swift-devel mailing list