File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,12 @@ namespace jni
128
128
{
129
129
return Seize (env, Object (jni::NewGlobalRef (env, obj).release ()));
130
130
}
131
+
132
+ template < class OtherTag >
133
+ bool IsInstanceOf (JNIEnv& env, const Class<OtherTag>& clazz) const
134
+ {
135
+ return jni::IsInstanceOf (env, obj, clazz);
136
+ }
131
137
};
132
138
133
139
template < class TagType >
@@ -157,4 +163,15 @@ namespace jni
157
163
{
158
164
return UniqueObject<TagType>(PointerToValue<Object<TagType>>(std::move (object)), ObjectDeleter<TagType>(env));
159
165
};
166
+
167
+
168
+ template < class OutTagType , class InTagType >
169
+ Object<OutTagType> Cast (JNIEnv& env, const Object<InTagType>& object, const Class<OutTagType>& clazz)
170
+ {
171
+ if (!object.IsInstanceOf (env, clazz))
172
+ {
173
+ ThrowNew (env, FindClass (env, " java/lang/ClassCastException" ));
174
+ }
175
+ return Object<OutTagType>(object.Get ());
176
+ }
160
177
}
You can’t perform that action at this time.
0 commit comments