Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As other answers suggest, <code>null</code>ing out the storage array is not directly verifiable by the public API. It would be simplest to add a <code>protected</code> method to allow direct examination of storage.</p> <p>As an alternative, consider the reason for this feature: any references held in your array should be released when <code>clear</code> is called. You can test this using only the public API, <code>Reference</code>s and some assumptions about GC (<a href="https://stackoverflow.com/questions/6968141/is-there-a-way-to-force-weak-and-or-soft-referenced-objects-to-be-gcd-in-java">Is there a way to FORCE weak and/or soft referenced objects to be GC&#39;d in Java?</a>).</p> <p>Place an object on the stack, retaining a <code>Reference</code>, and then <code>clear</code> it:</p> <pre><code>ReferenceQueue queue = new ReferenceQueue(); PhantomReference ref = addObjectToStackAndCreateReference(arrayStack, queue); arrayStack.clear() </code></pre> <p>with a separate utility method to keep that object off the Java stack, which could prevent collection:</p> <pre><code>private static PhantomReference addObjectToStackAndCreateReference(ArrayStack arrayStack, ReferenceQueue queue) { Object o = new Object(); PhantomReference ref = new PhantomReference(o, queue); arrayStack.push(o); return ref; } </code></pre> <p>Now, verify that there are no remaining references to the object, so the reference has been enqueued:</p> <pre><code>System.gc(); assertSame(ref, queue.remove()); </code></pre> <p>I'd recommend adding methods to make the testing simpler; however, that's one way you could test it without adding any test-only API.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload