Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ca.midnight.jnet.encryptors;
- public class LazyImmutableObject<E> {
- private E object;
- public LazyImmutableObject() {
- }
- public LazyImmutableObject(E object) {
- try {
- set(object);
- } catch (ImmutableObjectException e) {
- e.printStackTrace();
- }
- }
- public synchronized void set(E object) throws ImmutableObjectException {
- if(this.object != null)
- throw new ImmutableObjectException("You cannot define a value after it has been set");
- this.object = object;
- }
- public synchronized E get() {
- return object;
- }
- }
- class ImmutableObjectException extends Exception {
- private static final long serialVersionUID = 1L;
- public ImmutableObjectException(String string) {
- super(string);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement