在java中为int包装类指定一个int文字

时间:2017-08-08 02:07:03

标签: java int long-integer

为什么Long l = 3而不是Long l = 3L出现编译错误?

原始数据类型long同时接受33l。我了解3int字面值 - 但是它不能分配给Long包装对象? int只有32位,它不适合64位整数类型吗?

2 个答案:

答案 0 :(得分:4)

由于没有Longlong扩展自动装箱转换,自动装箱会从Long转换为int(但是首先,该值必须加宽long3L)。您可以按照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,反之亦然。

相关问题