android代码中的long和Long有什么区别? [英] What is the difference between long and Long in android code?

查看:27
本文介绍了android代码中的long和Long有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个 android 应用程序中编写一个 AsycTask.在那里我遇到了 Integer 和 Long 数据类型,但我不确定它们是什么.我尝试使用 long 代替 Long,但在 Eclipse 中出现错误,提示

I was trying to write an AsycTask in an android application. There I came across Integer and Long data types and I am not sure what they are. I tried using long in place Long, but I got an error in eclipse saying

'Syntax error on token "long", Dimensions expected after this token'.

推荐答案

Long 是一个类.long 是一个原语.这意味着 Long 可以为空,而 long 不能.Long 可以去任何需要 Object 的地方, long 不能(因为它不是一个类,它不是从 Object 派生的).

Long is a class. long is a primitive. That means Long can be null, where long can't. Long can go anywhere that takes an Object, long can't (since it isn't a class it doesn't derive from Object).

Java 通常会自动将 Long 转换为 long(反之亦然),但不会用于 null(因为 long 不能为 null),并且需要传递时需要使用 Long 版本一个类(例如在泛型声明中).

Java will usually translate a Long into a long automatically (and vice versa), but won't for nulls (since a long can't be a null), and you need to use the Long version when you need to pass a class (such as in a generic declaration).

这篇关于android代码中的long和Long有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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