diff --git a/README.md b/README.md index ab178f6..89cb1ed 100644 --- a/README.md +++ b/README.md @@ -39,12 +39,12 @@ OrderedCollections.OrderedSet{String} with 2 elements: "-Xmx1024M" "-Xrs" -julia> JavaCall.init() # Optionally, explicitly initialize the JVM. Do not use this in package `__init__()` to allow other packages to add class paths or options. +julia> JavaCall.init() # Call before using `jcall` or `jfield`. Do not use this in package `__init__()` to allow other packages to add classpaths or options. julia> jls = @jimport java.lang.System JavaObject{Symbol("java.lang.System")} -julia> out = jfield(jls, "out", @jimport java.io.PrintStream) +julia> out = jfield(jls, "out", @jimport java.io.PrintStream) # Third arg is optional, but helps type stability. JavaObject{Symbol("java.io.PrintStream")}(JavaCall.JavaLocalRef(Ptr{Nothing} @0x0000000003ecda38)) julia> jcall(out, "println", Nothing, (JString,), "Hello World") diff --git a/src/core.jl b/src/core.jl index 10b5a85..d04121a 100644 --- a/src/core.jl +++ b/src/core.jl @@ -424,7 +424,7 @@ function jfield(ref, field::AbstractString) assertroottask_or_goodenv() && assertloaded() field = listfields(ref, field)[] fieldType = jimport(gettype(field)) - jfieldID = get_field_id(ref, field, fieldType) + jfieldID = get_field_id(ref, field) _jfield(_jcallable(ref), jfieldID, fieldType) end diff --git a/test/runtests.jl b/test/runtests.jl index b19f085..3e67968 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -169,6 +169,9 @@ end t=JTest(()) t_fields = Dict(getname(f) => f for f in listfields(t)) + lazy_out = jfield(System, "out") # Not type stable + @test jcall(System_out, "equals", jboolean, (JObject,), lazy_out) == 0x01 + @testset "$ftype" for (name, ftype, valtest) in [ ("booleanField", jboolean, ==(true)) , ("integerField", jint, ==(100)) , ("stringField", JString, ==("A STRING")) ,