Here you can find the source of pop(Stack
public static <V> Object pop(Stack<Object> stack, Class<?> type)
//package com.java2s; //License from project: LGPL import java.util.Stack; public class Main { public static <V> Object pop(Stack<Object> stack, Class<?> type) { Object result = null;/*from w ww. ja v a 2 s. com*/ Object value = null; while (!((value = stack.pop()).getClass().isAssignableFrom(type))) { ; } if (value != null && value.getClass().isAssignableFrom(type)) result = value; return result; } }