Это старая версия документа.


A PCRE internal error occured. This might be caused by a faulty plugin

====== Weak Referencies ====== <code java> class TheStrong { public Object link; public Object getLink(){ return link; } public void print(Object newlink){ link = newlink; System.out.println("TheStrong: my link =" + getLink()); } } class TheWeak { public WeakReference<Object> link; public Object getLink(){ return link.get(); } public void print(Object newlink){ link = new WeakReference<>( newlink ); System.out.println("TheWeak: my link =" + getLink()); } } public class Test { public static void main(String[] args) throws IOException { TheStrong thestrong = new TheStrong(); thestrong.print(Arrays.asList(4,5,6)); TheWeak theweak = new TheWeak(); theweak.print(Arrays.asList(1,2,3)); Runtime r = Runtime.getRuntime(); r.gc(); System.out.println("TheWeak: its link=" + theweak.getLink()); System.out.println("TheStrong: its link=" + thestrong.getLink()); } } </code> Result: <code> TheWeak: my link =[1, 2, 3] TheStrong: my link =[4, 5, 6] TheWeak: its link=null TheStrong: its link=[4, 5, 6] </code>

dev/java/lang/weakrefs.1344091504.txt.gz · Последние изменения: 2012/08/04 18:45 — jamis7005
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0