Created
September 9, 2022 17:23
-
-
Save vishalratna-microsoft/0aaf54d1d65cf84cee68dea634340017 to your computer and use it in GitHub Desktop.
How covariant list allows the blocked operations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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