2012-05-25 80 views
1

以下代码显示的错误是:无法将对象转换为整数。我不知道我还会包括什么来施放它。将Java对象转换为整数

private RowFilter filter(final int itemsPerPage,final int target) { 
     return new RowFilter() { 
      public boolean include(Entry entry) { 

       /* HERE I AM RECEIVING ERROR: Multiple markers at this line 
       - Type mismatch: cannot convert from Object to int 
       - Cannot cast from Object to int */ 
       int ei = (int) entry.getIdentifier(); 

       return (target * itemsPerPage <= ei && ei < target 
         * itemsPerPage + itemsPerPage); 
      } 
     }; 
    } 
+1

这将是一个“整数”(对象)而不是“整数”(原始)。为了更快地获得更好的帮助,请发布[SSCCE](http://sscce.org/)。 –

+0

你可以把Entry的getidentifier方法签名? – BachT

+0

@AndrewThompson如果它是一个Integer对象,那么这个代码不应该继续工作,因为它会自动取消装箱? – Hassan

回答

5

你想要的是:

int ei = ((Integer) entry.getIdentifier()).intValue(); 
0

我觉得你的方法在这里返回Integer对象,如果这是你需要做这样的案例:

int ei = ((Integer)entry.getIdentifier()).intValue();