About Question enthuware.ocpjp.v8.2.1860 :
Posted: Sun Nov 29, 2015 9:43 am
I do not agree with this answer: IntFunction does not "avoid additional cost associated with auto-boxing/unboxing" by virtue of its own nature. It's developer's responsability making a good use of Function or IntFunction, both of them can cause auto-boxing/unboxing if misused
or avoid it if properly used
I'd simply say that IntFunction accepts primitive integers.
Code: Select all
// bad use
new IntFunction<String>(){
@Override
public String apply(int value) {
return Integer.toString(value);
}
}.apply(new Integer(1));
new Function<Integer,String>(){
@Override
public String apply(Integer value) {
return value.toString();
}
}.apply(1);
Code: Select all
// good use
new IntFunction<String>(){
@Override
public String apply(int value) {
return Integer.toString(value);
}
}.apply(1);
new Function<Integer,String>(){
@Override
public String apply(Integer value) {
return value.toString();
}
}.apply(new Integer(1));