Sobes.tech
Junior — Middle

Do you use generics in development?

sobes.tech AI

Answer from AI

Yes, generics are actively used in Java to ensure type safety and code reusability. They allow creating classes, interfaces, and methods that work with different data types, avoiding type casting and runtime errors.

Example of using generics in Java:

public class Box<T> {
    private T content;

    public void setContent(T content) {
        this.content = content;
    }

    public T getContent() {
        return content;
    }
}

// Usage:
Box<String> stringBox = new Box<>();
stringBox.setContent("Example");
String value = stringBox.getContent();
Do you use generics in development? — Java - sobes.tech