P
Patricia Shanahan
Here is a sample program that uses auto-boxing and auto-unboxing:
public class AutoBoxQuestion {
public static void main(String[] args) {
/* This does seem better than writing out
{new Long(1), new Long(2), new Long(3), new Long(4)}*/
Long[] data = new Long[]{1L,2L,3L,4L};
long total = 0;
for(Long val: data){
// Or should this be val.getLong()?
total += val;
}
System.out.println("Total is "+total);
}
}
Is it good style to depend on the auto-boxing and auto-unboxing?
My real program is a little more complicated, involving retrieving
results from a List<Future<Long>>, but contains the same principle of
adding up values represented as Long objects.
Patricia
public class AutoBoxQuestion {
public static void main(String[] args) {
/* This does seem better than writing out
{new Long(1), new Long(2), new Long(3), new Long(4)}*/
Long[] data = new Long[]{1L,2L,3L,4L};
long total = 0;
for(Long val: data){
// Or should this be val.getLong()?
total += val;
}
System.out.println("Total is "+total);
}
}
Is it good style to depend on the auto-boxing and auto-unboxing?
My real program is a little more complicated, involving retrieving
results from a List<Future<Long>>, but contains the same principle of
adding up values represented as Long objects.
Patricia