int无法解除引用错误 [英] int cannot be dereferenced error

查看:97
本文介绍了int无法解除引用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码中有一个int无法解除引用的错误我//错误在这里。我很困惑,因为变量b用于引用行后面的empl数组中的一个点而不显示为错误。那么我该如何解决这个问题,为什么会产生错误呢?
我将不胜感激任何帮助。示例代码也很棒,因为这似乎是我学得最好的方式。谢谢!

I have the int cannot be dereferenced error in the below code where I have //error is here. I'm confused because the variable b is used to reference a spot in the empl array later in the line without showing as an error. So how do I fix this and why is it generating an error? I would appreciate any help. Example code would be great too as that seems to be the way I learn best. Thanks!

public static void bubbleSort(Employee[] empl) {
    for (int a = 1; a < empl.length; a++) 
    {
        for (int b = 0; b < empl.length - a; b++) 
        {
            if (((empl[b].//error is here
                    getEmployeeNumber()).compareTo
                   ((empl[b + 1].getEmployeeNumber()))) > 0) 
            {
               // swap employees[b] with employees[b+1]
               Employee temp = empl[b];
               empl[b] = empl[b + 1];
               empl[b + 1] = temp;
            }
        }
    }
}

编辑:欢迎使用员工编号对数组进行排序的任何其他建议。

Any other suggestions for sorting the array by Employee Number are welcome.

推荐答案

getEmployeeNumber()显然返回 int

int 是原始类型,而不是对象。

因此,您无法在其上调用 compareTo()等方法。

int is a primitive type, not an object.
Therefore, you cannot call methods like compareTo() on it.

这篇关于int无法解除引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆