Skip to content

Instantly share code, notes, and snippets.

@vishalratna-microsoft
Created September 9, 2022 17:23
Show Gist options
  • Save vishalratna-microsoft/0aaf54d1d65cf84cee68dea634340017 to your computer and use it in GitHub Desktop.
Save vishalratna-microsoft/0aaf54d1d65cf84cee68dea634340017 to your computer and use it in GitHub Desktop.
How covariant list allows the blocked operations.
package com.tutorials.vishal;
import com.tutorials.vishal.hierarchy.BaseWork;
import com.tutorials.vishal.hierarchy.RxWork;
import com.tutorials.vishal.hierarchy.Scheduler;
import java.util.ArrayList;
import java.util.List;
public class DemoClass {
void driver() {
List<BaseWork> baseWorks = new ArrayList<>();
List<RxWork> rxWorks = new ArrayList<>();
baseWorks.add(new RxWork());
baseWorks.add(new BaseWork());
startJob(baseWorks); // Bingo!
startJob(rxWorks);
}
void startJob(List<? extends BaseWork> incomingWork) {
// validate the work and submit.
for (BaseWork b : incomingWork) {
Scheduler.submit(b);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment