Package generic.util
Class DequePush<E>
- java.lang.Object
-
- generic.util.DequePush<E>
-
- Type Parameters:
E
- the type of element pushed to the stack
- All Implemented Interfaces:
java.lang.AutoCloseable
public class DequePush<E> extends java.lang.Object implements java.lang.AutoCloseable
A context utility allowing stack management via a try-with-resources block
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static <E> DequePush<E>
push(java.util.Deque<E> stack, E elem)
Push an element to the given stack
-
-
-
Field Detail
-
stack
protected java.util.Deque<E> stack
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
push
public static <E> DequePush<E> push(java.util.Deque<E> stack, E elem)
Push an element to the given stack- Parameters:
stack
- the stackelem
- the element- Returns:
- a context used to pop the element
This is an idiomatic convenience, as in a try-with-resources block:
Deque<String> stack = new LinkedList<>(); try(DequePush<?> p = DequePush.push(stack, "Hello, World!\n")) { System.out.println(stack.peek()); }
-
-