Hi,
I have utility method in Arrays class, that lets to skip all that type
confusion:
public static <T, P extends T> NSArray<T> create(P... objects) {
return new NSArray<T>(objects);
}
Then you don't need to worry about types when creating array this way, though
type is checked for assignments.
So the following compiles:
NSArray<Integer> arr = Arrays.create(1, 2, 3);
while this one doesn't:
NSArray<Double> arr = Arrays.create(1, 2, 3); // compile time error
I think it's the best way to create an array, as you specify what will be kept
in there just once, not three times like in
NSArray<Integer> arr = new NSArray<Integer>(new Integer [] {...});
not mentioning readability
Regards,
Jedrzej Sobanski
On Oct 27, 2009, at 5:17 PM, Alex Johnson wrote:
Just to summarize, the problem was that:
new NSArray( new int [] { ... } )
translates to the single-object NSArray constructor: NSArray( Object ), whereas:
new NSArray( new Integer [] { ... } )
translates to the object-array constructor: NSArray( Object [] ), because an
int [] is not a subtype of Object [] (unlike an Integer []), and I don't think
Java will auto-box an int [] into an Integer [].
This has been mentioned on the list before, but using Java's auto-boxing --
especially without using generics -- causes a lot of these head-scratcher bugs.
My advice is to disable it, by telling the compiler to treat boxing and
unboxing as errors.
Alex Johnson
アレックス ジャンサン
Hi!
You don't have to do new Integer(x) for all the integers. I have this on
my code and it works:
private NSArray<Integer> monthList = new NSArray<Integer>( new Integer[]
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 } );
Try disabling 'Boxing and unboxing conversions:' in Preferences -> Java ->
Compiler -> Errors/Warnings -> Potential programming problems
I have a wo popup button
YearPopUpButton: WOPopUpButton {
item = intSelection;
list = YearList;
selection = anAppliedClass.appliedYear;
}
and the relevant code is
public NSArray YearList = new NSArray(new int[]{2000, 2001, 2002,
2003, 2004, 2005, 2006, 2007, 2008, 2009});
public int intSelection;
appliedYear is an Integer.
When run, I get:
While trying to set the field "intSelection" on an object of type
edu.stanford.ee.classmgmt.apply.ui.AppliedClassPage we expected a int
but received a [I with a value of [...@70d9cbcb. This often happens if
you forget to use a formatter.
Setting a formatter doesn't seem to help. I'm guessing I need some
indirection to setting the appliedYear value, but it seems the error
is more due to the fact that its not liking the NSArray. Do I need to
generate a list of new Integer(2000), new Integer(2001).. etc?
<smime.p7s> _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list
([email protected]<mailto:[email protected]>)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/jsobanski%40upcbroadband.com
This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]