android-运算符==不能应用于Kotlin中的’Long’和’Int’

android-运算符==不能应用于Kotlin中的’Long’和’Int’,第1张

概述我正在尝试在Kotlin中实现MikePenz的NavigationDrawer(https://github.com/mikepenz/MaterialDrawer)的某些部分.从那以后,我只遇到了几个问题,主要是关于 *** 作符的.这是实例化抽屉本身的代码的一部分.除了在int和Long变量上使用==运算符的地方,AndroidStudio不会引发任何错误:

我正在尝试在Kotlin中实现Mike Penz的NavigationDrawer(https://github.com/mikepenz/MaterialDrawer)的某些部分.从那以后,我只遇到了几个问题,主要是关于 *** 作符的.这是实例化抽屉本身的代码的一部分.除了在int和Long变量上使用==运算符的地方,AndroID Studio不会引发任何错误:

        // Create the Drawer        result = DrawerBuilder()                .withSlIDerBackgroundcolor(ContextCompat.getcolor(applicationContext, R.color.top_header))                .withActivity(this)                .withToolbar(toolbar)                .withHasStableIDs(true)                .withItemAnimator(AlphaCrossFadeAnimator())                .withAccountheader(headerResult!!)                .addDrawerItems(                        PrimaryDrawerItem().withname(R.string.drawer_item_profile).withIcon(FontAwesome.Icon.faw_user).withIDentifIEr(1).withSelectable(false).withIconcolor(ContextCompat.getcolor(applicationContext, R.color.icon_grey)).withTextcolor(ContextCompat.getcolor(applicationContext, R.color.stroke)),                        PrimaryDrawerItem().withname(R.string.drawer_item_create).withIcon(FontAwesome.Icon.faw_paint_brush).withIDentifIEr(2).withSelectable(false).withIconcolor(ContextCompat.getcolor(applicationContext, R.color.icon_grey)).withTextcolor(ContextCompat.getcolor(applicationContext, R.color.stroke)),                        PrimaryDrawerItem().withname(R.string.drawer_item_yaanich_news).withIcon(FontAwesome.Icon.faw_newspaper_o).withIDentifIEr(3).withSelectable(false).withIconcolor(ContextCompat.getcolor(applicationContext, R.color.icon_grey)).withTextcolor(ContextCompat.getcolor(applicationContext, R.color.stroke)),                        PrimaryDrawerItem().withname(R.string.drawer_item_my_groups).withIcon(FontAwesome.Icon.faw_users).withIDentifIEr(4).withSelectable(false).withIconcolor(ContextCompat.getcolor(applicationContext, R.color.icon_grey)).withTextcolor(ContextCompat.getcolor(applicationContext, R.color.stroke)),                        PrimaryDrawerItem().withname(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog).withIDentifIEr(5).withSelectable(false).withIconcolor(ContextCompat.getcolor(applicationContext, R.color.icon_grey)).withTextcolor(ContextCompat.getcolor(applicationContext, R.color.stroke))                )                .withOnDrawerItemClickListener { vIEw, position, drawerItem ->                    if (drawerItem != null) {                        var intent: Intent? = null                        if (drawerItem.IDentifIEr == (1) {                            intent = Intent(this, UserProfileActivity::class.java)                        } else if (drawerItem.IDentifIEr == 2) {                            intent = Intent(this, YeetActivity::class.java)                        } else if (drawerItem.IDentifIEr == 3) {                            intent = Intent(this, RSSActivity::class.java)                        } else if (drawerItem.IDentifIEr == 4) {                            intent = Intent(this, GroupsActivity::class.java)                        } else if (drawerItem.IDentifIEr == 5) {                            intent = Intent(this, UserSettingsActivity::class.java)                        }                        if (intent != null) {                            this.startActivity(intent)                        }                    }                    false                }                .withSavedInstance(savedInstanceState)                .withShowDrawerOnFirstLaunch(true)                .build()        RecyclerVIEwCacheUtil<IDrawerItem<*, *>>().withCacheSize(2).apply(result!!.recyclerVIEw, result!!.drawerItems)        if (savedInstanceState == null) {            result!!.setSelection(21, false)            headerResult!!.activeProfile = profile        }    }

错误:

如果(drawerItem.IDentifIEr ==(1)

如果(drawerItem.IDentifIEr == 2)

运算符==不能应用于’Long and”Int’

@R_419_6120@:

只需在右侧长时间使用

if (drawerItem.IDentifIEr == 1L)

编辑:之所以需要这样做,是因为Kotlin不会将Ints提升为Longs(或更普遍的是,不会扩展类型);左边是Long,右边是Int,这会导致错误.明确指出右侧是Long可以修复错误.

总结

以上是内存溢出为你收集整理的android-运算符==不能应用于Kotlin中的’Long’和’Int’全部内容,希望文章能够帮你解决android-运算符==不能应用于Kotlin中的’Long’和’Int’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1095219.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存