Community
Participate
Working Groups
I20050617-0010 void m(Object obj) { int i= obj; } In a 5.0 project, a quick fix proposes 'Add cast to (int)', which is wrong. The right cast here would be to (Integer), which would then be autounboxed. In a 1.4 project, no 'Add cast ..' quick fix is proposed, which is correct.
Created attachment 115687 [details] patch Here is a little patch for this issue. I refactored out the boxing conversion into a static method to avoid having duplicate logic in the quick fix and the preview.
I am wondering if the patch solves as well (JDK1.6) the problem with Integer mu=5.0f cause the proposal here has to be (int) and not Integer. Additionally I am interested if the proposed fix works as well with Object obj=true; boolean mu= obj; I guess the patch should apply to all primitives.
Released to HEAD with a few corrections. (In reply to comment #2) > I am wondering if the patch solves as well (JDK1.6) the problem with > > Integer mu=5.0f > > cause the proposal here has to be (int) and not Integer. That's bug 285573. > Additionally I am interested if the proposed fix works as well with > > Object obj=true; > boolean mu= obj; > > I guess the patch should apply to all primitives. Yes, fixes all primitives.
While looking a bit closer at bug 285573, I realized that the existing code actually used ITypeBinding#isCastCompatible(ITypeBinding type) the wrong way 'round and this worked only with huge luck. I reworked the fix a bit in HEAD.