setId
takes a capital-L Long
, which is Java's wrapper around lowercase-l long
(AKA 64-bit integer). Because of this, Java easily knows how to convert a long
to a Long
without you doing anything special. So, like the other answers say, you could simply do setId(1L)
, which is giving it a long
, which it easily converts to a Long
.
However, if you must use a 32-bit int
, you must first convert it to a long
or a Long
, so Java knows how to handle it. You see, Java does not know implicitly how to convert a lowercase-i int
to an uppercase-L Long
, only to an uppercase-I Integer
(the wrapper class around int
).
So, assuming your int's name is i
, you can use these as well:
setId((long)i); // Cast your int to a long, which Java can turn into a Long
setId((Long)(long)i); // Cast your int to a long, then that long to a Long
setId(new Long(i)); // Create a new Long object based on your int
setId(Long.valueOf(i)); // Get the Long version of your int