19

Вопрос по java – Получение всех экземпляров класса [дубликата]

Possible Duplicate:
Is there a simple way of obtaining all object instances of a specific class in Java

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Apr 09, 2012, 9:06 AMот

2ответа

19

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

  class MyObject {
    private static List instances = new ArrayList();

    public static MyObject createMyObject() {
    MyObject o = new MyObject();
    instances.add(new java.lang.ref.WeakReference(o));
    return o;
    }

    public static List getInstances() {
    return instances;
    }

    private MyObject() {
    // Not allowed 
    }
  }
7

Error: User Rate Limit ExceededotherError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

RelatedQuestions