Exemplo n.º 1
0
    @Override
    public <T> T getIndex(Class<T> clazz) {
      T bi = null;
      synchronized (cb) {
        @SuppressWarnings("unchecked")
        SoftReference<T> softRef = (SoftReference<T>) cb.getIndex();
        if (softRef != null) bi = softRef.get();

        if (bi == null) {
          try {
            bi = clazz.newInstance();
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
          cb.setIndex(new SoftReference<T>(bi));
        }
      }

      return bi;
    }