WeakReference symbol cannot be found
Already import the weakreference but the compiler cannot find the symbol, what wrong? There a memory leak in DumpReceiver.java I thought weakreference might free after used?
import java.lang.ref.WeakReference;
Receiver r = new DumpReceiver(System.out);
WeakReference<Receiver> wr = new WeakReference<DumpReceiver>(r);
MidiInDump.java:64: cannot find symbol
symbol : constructor WeakReference(javax.sound.midi.Receiver)
location: class java.lang.ref.WeakReference<DumpReceiver>
WeakReference<Receiver> wr = new Wea开发者_Python百科kReference<DumpReceiver>(r);
^
Look closely at the error message. It's not talking about the class (it's finding that just fine). It is talking about the constructor. It doesn't find a constructor that takes a javax.sound.midi.Receiver
argument on the type WeakReference<DumpReceiver>
. Looking at the JavaDoc of WeakReference<T>
there is one constructor that takes an argument of type T
.
You're trying to create a WeakReference<DumpReceiver>
but try to pass in an object of type javax.sound.midi.Receiver
. You either need to create a WeakReference<Receiver>
instead or change the variable r
to be of type DumpReceiver
.
精彩评论