6
I’m trying to learn how to run the class SwingWorker<T,V>
, I’ve even done another question regarding one of its methods.
Looking at the source code of this class, I found the method publish()
written as follows:
SafeVarargs
@SuppressWarnings("varargs") // Passing chunks to add is safe
protected final void publish(V... chunks) {
synchronized (this) {
if (doProcess == null) {
doProcess = new AccumulativeRunnable<V>() {
@Override
public void run(List<V> args) {
process(args);
}
@Override
protected void submit() {
doSubmit.add(this);
}
};
}
}
doProcess.add(chunks);
}
In the "signature" of the method, it receives V... chunks
as argument. However, after testing this class a little, I noticed that even if I define this type V
when starting a variable, example SwingWorker<Void, Integer> worker;
(The V
is represented by Integer
), and pass the publish()
no parameter, no syntax error is generated, and the code works normally.
Given the above, I question: how is this way of passing arguments without being mandatory and how the JVM treats this type of method?
Related? What mean the reticence in the parameters of a method?
– Renan Gomes
@But I didn’t know it was the name of this type of parameter passage.
– user28595