为什么Long l = 3
而不是Long l = 3L
出现编译错误?
原始数据类型long
同时接受3
和3l
。我了解3
是int
字面值 - 但是它不能分配给Long
包装对象? int
只有32位,它不适合64位整数类型吗?
答案 0 :(得分:4)
由于没有Long
到long
扩展和自动装箱转换,自动装箱会从Long
转换为int
(但是首先,该值必须加宽从long
到3L
)。您可以按照Long l = Long.valueOf(3);
或
Long l = (long) 3;
或
function addTrainer() {
var modal = document.getElementById('add-trainers-form');
var span = document.getElementsByClassName("close")[0];
$(this).click(function(event) { //this part of code works fine,
$('.modal').css('display', 'block');
});
$(span).click(function(event) { //not working
// modal.style.display = "none";
$('.modal').css('display', 'inherit');
});
$(window).click(function(event) { //this also works fine
if (event.target == modal) {
modal.style.display = "none";
}
});
$('#add-trainer-btn').click(function() { //not working
$('.modal').css('display', 'none');
});
}
答案 1 :(得分:0)
有关其他答案:
3L
等于(long)3
- >将其解析为3L,因为它是一个长文字
3是整数字
3L是长文字
简而言之,它们彼此不同,这就是为什么你需要将int解析为long,反之亦然。