Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Java对象强制转换为整数_Java_Swing_Object_Integer_Int - Fatal编程技术网

将Java对象强制转换为整数

将Java对象强制转换为整数,java,swing,object,integer,int,Java,Swing,Object,Integer,Int,下面代码显示的错误是:无法将对象强制转换为整数。我不知道还有什么我会包括投它 private RowFilter filter(final int itemsPerPage,final int target) { return new RowFilter() { public boolean include(Entry entry) { /* HERE I AM RECEIVING ERROR: Multiple mark

下面代码显示的错误是:无法将对象强制转换为整数。我不知道还有什么我会包括投它

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);
            }
        };
    }
private行筛选器筛选器(最终整数项页面,最终整数目标){
返回新的行筛选器(){
公共布尔包含(条目){
/*这里我接收到错误:这一行有多个标记
-类型不匹配:无法从对象转换为int
-无法从对象强制转换为int*/
int ei=(int)entry.getIdentifier();
return(target*itemsPerPage您想要的是:

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

我认为您的方法在这里返回
Integer
对象,如果是这种情况,您需要这样做:

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

它将是一个
整数
(对象),而不是
int
(原语)。为了更快地获得更好的帮助,请发布一个。您可以放置条目的getidentifier方法签名吗?@AndrewThompson如果它是整数对象,此代码是否仍然可以工作,因为它将自动解除绑定?太正确了,所有代码都可以工作,但如果没有,很难说出OP的错误:-)