Assigning an int literal to a long wrapper class in java
问题 Why is there a compilation error with Long l = 3 and not with Long l = 3L ? The primitive data type long accepts both 3 and 3l . I understand that 3 is an int literal - but it can't be assigned to a Long wrapper object? int is only 32 bits shouldn't it fit in a 64 bit integer type? 回答1: Because there isn't an int to Long widening and autoboxing conversion, autoboxing converts from long to Long (but first the value must be widened from an int to a long ). You could do 3L as you have, or Long l