you can't cast Integer to Long, even though you can convert from int to long. For an individual value which is known to be a number and you want to get the long value, you could use:
package com.mkyong.example;
public class TestInteger {
public static void main(String[] args) {
Integer num = 1;
System.out.println(num); // 1
Long numInLong = Long.valueOf(num);
System.out.println(numInLong); // 1
}
}
References :
https://www.mkyong.com/java/java-convert-integer-to-long/
https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html#valueOf(long
https://www.mkyong.com/java/java-convert-integer-to-long/
https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html#valueOf(long
0 komentar:
Post a Comment