Поясните, что значит "super(name)" ТУТ:
public static class PrintListThread extends Thread {
public PrintListThread(String name) {
super(name);
}
Или это для экземпляров класса PrintListThread, которые задают имя для родительского PrintListThread?
и откуда взялся метод getName()?
public void run() {
printList(getList(20), getName());
}
Кажется раньше метод прописывали всегда? getList() выше прописан же?
Весь код ниже:
public class Solution {
public static void main(String[] args) throws InterruptedException {
PrintListThread firstThread = new PrintListThread("firstThread");
PrintListThread secondThread = new PrintListThread("secondThread");
firstThread.start();
firstThread.join();
secondThread.start();
}
public static void printList(List<String> list, String threadName) {
for (String item : list) {
System.out.println(String.format("%s : %s", threadName, item));
}
}
public static List<String> getList(int n) {
List<String> result = new ArrayList<String>();
if (n < 1) return result;
for (int i = 0; i < n; i++) {result.add(String.format("String %d", (i + 1)));}
return result;}
public static class PrintListThread extends Thread {
public PrintListThread(String name) {
super(name);
}
public void run() {
printList(getList(20), getName());
}
}
}