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:
AutoCloseable
A context utility allowing stack management via a try-with-resources block
-
Field Summary
-
Constructor Summary
-
Method Summary
-
Field Details
-
stack
-
-
Constructor Details
-
DequePush
-
-
Method Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
push
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()); }
-