erdemolkun / plist

Automatically exported from code.google.com/p/plist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enhancement : Add functions to get Java types from NSObjects

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?
1. Example : Get an Int from NSDictionary 

What is the expected output? What do you see instead?
- expected : An int returned
- instead : A NSObject

What version of the product are you using? On what operating system?
r100 on MacOSX

Please provide any additional information below.

To explain the enhancement, here is a static function I wrote to help myself :

public static <T> T typeFromNSObject(NSObject object, Class<T> expectedType){
    return (expectedType.isInstance(object)) ? expectedType.cast(object) : null;
}

Then, some functions of NSObject could be :
public int toInt(){
    return typeFromNSObject(this,Integer.class).intValue();
}

Original issue reported on code.google.com by djl...@gmail.com on 11 Apr 2013 at 12:26

The function .toJavaObject() gives a native java object for every NSObject. The 
method also performs deep conversions, so a NSArray of NSNumbers will be turned 
into an Array of ints/doubles/etc.

Additional methods for conversion (e.g. toInt(), toDouble(), toWhatever(), ...) 
will not be added to NSObject. But functions like these exist already for all 
subclasses of NSObject. And for the NSObject level just use the aforementioned 
toJavaObject().

The reverse (turning Java objects to NSObjects) can be done with 
NSObject.wrap(...)

What else do you need?

Original comment by daniel.dreibrodt on 11 Apr 2013 at 2:55

Original comment by daniel.dreibrodt on 11 Apr 2013 at 2:55

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect
Ok for the toJavaObject() method, my wish was to get typed object without 
unchecked casts.

Original comment by developp...@gmail.com on 16 Apr 2013 at 8:48

Please use the appropriate methods of the NSObject subclasses to get typed 
objects.

Original comment by daniel.dreibrodt on 1 Apr 2015 at 5:08

  • Changed state: WontFix