SCJP: can't widen and then box, but you can box and then widen

前端 未结 5 747
余生分开走
余生分开走 2020-12-17 03:05

I\'m studying for the SCJP exam and I ran into an issue I can\'t really wrap my head around.

The book says you can\'t widen and then box, but you can box and then wi

5条回答
  •  臣服心动
    2020-12-17 03:27

    The reason why "widening then boxing" is not allowed may be because of the following reason (page 249 of the SCJP book):

    Java 5's designers decided that the most important rule should be that preexisting code should function the way it used to, so since widening capability already existed,a method that is invoked via widening shouldn't lose out to a newly created method that relies on boxing

提交回复
热议问题