Skip to content

Calling java.lang.String constructor doesn't return reference to String object #146

@amserra

Description

@amserra

Good afternoon. I've been working on a project with JavaCall and may have stumbled across a bug.
Calling the constructor of the wrapper class Integer, I get a reference to the object on variable int_obj, which I can use to call instance methods.

> j_integer = @jimport java.lang.Integer
> int_obj = j_integer((jint, ), Int32(9))
> jcall(int_obj, "floatValue", Float32, ())
> 9.0

However, calling the constructor of class String, this results not in a reference to the String object (as expected), but in the String value itself.

> j_string = @jimport java.lang.String
> str = j_string((JString, ), "foo")
> jcall(str, "trim", JString, ())
> ERROR: LoadError: MethodError: no method matching jcall(::String, ::String, ::Type{JavaCall.JavaObject{Symbol("java.lang.String")}}, ::Tuple{})

I'm running this on a 64-bit Julia version in Mac OS with JULIA_COPY_STACKS on. I use the code in the documentation to initialize the JVM:

using JavaCall
JavaCall.init(["-Xmx128M"])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions