Sobes.tech
Junior — Middle

Can you explain what a list of interfaces in programming is?

sobes.tech AI

Answer from AI

A list of interfaces in programming is a collection of objects that implement a specific interface. An interface defines a set of methods that a class must implement but does not contain their implementation. A list of interfaces allows working with different objects through a common interface, ensuring polymorphism.

For example, in Java, you can create a list of objects that implement the Runnable interface:

List<Runnable> tasks = new ArrayList<>();
tasks.add(() -> System.out.println("Task 1"));
tasks.add(() -> System.out.println("Task 2"));

for (Runnable task : tasks) {
    task.run();
}

Here, the tasks list contains objects that can be executed via the run() method, regardless of their specific class.