I'm trying to create a TreeSet in objc using the J2ObjC cocoapod package v0.9.6.1 (the latest at this time).
#include <java/util/TreeSet.h>
id<JavaUtilSet> set = [[JavaUtilTreeSet alloc] init];
for (NSString* setval in (NSArray*)values) {
[set addWithId:setval]; // <== JavaLangClassCastException
}
However, this throws an exception:
JavaLangClassCastException: java.lang.String is not Comparable
indicating that the NSString
(there is no separate JavaLangString
in j2objc) won't cast to a Comparable
object. The exception is thrown from
JavaUtilTreeMap findWithId:withJavaUtilTreeMap_RelationEnum:
A previous 0.9 version (8ee9dc12ad) worked just fine with my above code. If I change JavaUtilTreeSet
to be JavaUtilHashSet
then it works.
Is this a bug in v0.9.6.1 of J2ObjC or am I doing something wrong here?