Type Bound

Noun · Development

Definitions

  1. A constraint on a generic type parameter that restricts it to types satisfying a specified interface, trait, or superclass — such as `<T extends Comparable<T>>` in Java or `T: Display + Clone` in Rust. Type bounds ensure the generic code can safely call methods or access properties guaranteed by the bound.

    In plain English: A rule that limits what types can be plugged into a generic slot, ensuring they have certain capabilities.

    Example: "Add a type bound of `T: Serialize` so the compiler guarantees anything passed to this function can be serialized to JSON."

Related Terms