Home

jclass

jclass is a JNI type used in native code (C or C++) to represent a reference to a Java class. In JNI, a class reference refers to an instance of the Java class object (the runtime java.lang.Class object) and is used when native code needs to interact with Java classes, such as accessing static methods or fields or obtaining method identifiers.

A jclass value is typically obtained by calling FindClass from native code, or it can be received

Lifecycle and reference management are important aspects of working with jclass. References returned by JNI functions

Notes and considerations include that a jclass indeed represents a reference to a Java class object, typically

as
a
parameter
to
a
native
method
that
exposes
a
Java
class
to
native
code.
Once
obtained,
the
reference
may
be
used
to
query
and
invoke
static
members
via
functions
such
as
GetStaticMethodID,
GetStaticFieldID,
and
to
call
static
methods
with
CallStatic...
variants.
It
can
also
be
passed
to
methods
that
require
a
class
reference,
including
calls
that
need
a
class
argument
through
the
jvalue
union.
are
usually
local
to
the
native
method
and
are
automatically
freed
when
the
native
method
returns.
If
a
class
reference
must
be
kept
longer
than
the
duration
of
a
native
method,
it
should
be
converted
to
a
global
reference
using
NewGlobalRef
and
later
released
with
DeleteGlobalRef.
Local
references
can
be
freed
earlier
with
DeleteLocalRef
if
desired.
java.lang.Class,
but
it
is
used
in
native
code
as
a
distinct
JNI
type.
In
multi-threaded
contexts,
class
references
may
depend
on
the
appropriate
class
loader,
and
in
some
cases
FindClass
must
be
performed
in
the
correct
loader
context
to
succeed.
The
jvalue
union
used
for
method
calls
also
includes
a
jclass
component,
enabling
its
use
as
an
argument
in
certain
JNI
invocation
variants.