Why does a compilation error occur when declaring a stack containing a Long object in Java, popping a number, and then casting it to long?
There is a stack containing a long-sized range, and you want to multiply two values by popping them from the stack. Stack<Long> s = new Stack<>(); s.push(1000000000); s.push(1000000000); long result = (long) s.pop() * (long) s.pop(); However, doing such an operation gives an error. Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long… Read More Why does a compilation error occur when declaring a stack containing a Long object in Java, popping a number, and then casting it to long?