Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Class<>::Find() for Array objects #9

Closed
wants to merge 1 commit into from

Conversation

kkaefer
Copy link
Member

@kkaefer kkaefer commented Apr 13, 2017

Class<>::Find currently calls the tag's Name() method, which means that it's currently quite ugly to retrieve an array class (e.g. Object[]) since you'd have to specify [Ljava/util/Object; as the Name() of the tag.

Instead, we could implement a Name() function on Array<Object<...>> specialization, so you could do jni::Class<jni::Array<jni::Object<...>>>::Find(env).

@jfirebaugh
Copy link
Contributor

There's a lack of parallelism here which concerns me:

  • The class of Object<ObjectTag> is Class<ObjectTag>
  • But the class of Array<ObjectTag> is Class<Array<ObjectTag>>

In one case the Class template parameter is a tag object, in the other it's Array<>, which is in a different type category.

One alternative is Class<ArrayTag<ObjectTag>>, with:

template < class TagType >
struct ArrayTag
   {
    static const char * Name() { return TypeSignature<Array<Object<TagType>>>()(); }
   };

Another alternative is to define a separate ArrayClass template. This has the advantage that it could omit New (which is expressly prohibited for array classes) and GetConstructor. Not sure about all of the remaining methods. Array classes inherit from Object , so GetMethod is definitely relevant, but I'm not sure about anything else.

@jfirebaugh
Copy link
Contributor

This was addressed as part of #40, via addition of ArrayTag<T>, which was needed for other reasons. So you can now do jni::Class<jni::ArrayTag<jni::Object<>>>::Singleton(env) or jni::Class<jni::ArrayTag<jni::jlong>>::Singleton(env).

@jfirebaugh jfirebaugh closed this Sep 5, 2018
@jfirebaugh jfirebaugh deleted the 9-class-find-for-array-classes branch September 5, 2018 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants