Skip to content

Commit bf9ae91

Browse files
committed
Add two arg jfield
1 parent 2da3217 commit bf9ae91

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/core.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ get_method_id(method::JMethod) = @checknull JNI.FromReflectedMethod(method)
399399
(m::JMethod)(obj, args...) = jcall(obj, m, args...)
400400

401401

402+
"""
403+
jfield(ref, field, [fieldType])
404+
405+
Get a pointer to a field of of a Java class or object.
406+
* `ref` could be a JavaObject{T} type or a JavaObject
407+
* `field` can be an AbstractString or JField
408+
* `fieldType` is a Type
409+
"""
402410
function jfield(ref, field, fieldType)
403411
assertroottask_or_goodenv() && assertloaded()
404412
jfieldID = get_field_id(ref, field, fieldType)
@@ -412,6 +420,14 @@ function jfield(ref, field)
412420
_jfield(_jcallable(ref), jfieldID, fieldType)
413421
end
414422

423+
function jfield(ref, field::AbstractString)
424+
assertroottask_or_goodenv() && assertloaded()
425+
field = listfields(ref, field)[]
426+
fieldType = jimport(gettype(field))
427+
jfieldID = get_field_id(ref, field, fieldType)
428+
_jfield(_jcallable(ref), jfieldID, fieldType)
429+
end
430+
415431
function get_field_id(typ::Type{JavaObject{T}}, field::AbstractString, fieldType::Type) where T
416432
@checknull JNI.GetStaticFieldID(Ptr(metaclass(T)), String(field), signature(fieldType))
417433
end

0 commit comments

Comments
 (0)