# Type Parameter

A type parameter is a parameter used to define generic classes, functions, type aliases, or generic types.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## New in Symfony 8.2: Generics and Stricter Types in the Serializer

DevFeed: [New in Symfony 8.2: Generics and Stricter Types in the Serializer](<https://devfeed.tech/articles/new-in-symfony-8-2-generics-and-stricter-types-in-the-serializer-102321.md>)

Original publisher: [Read original article](<https://symfony.com/blog/new-in-symfony-8-2-generics-and-stricter-types-in-the-serializer>)

Author: Javier Eguiluz

Published: 2026-10-27T08:12:00Z

Content type: release

Language: en

Sources: [Symfony](<https://devfeed.tech/sources/symfony-blog.md>)

Topics: [Symfony](<https://devfeed.tech/topics/symfony.md>), [union types](<https://devfeed.tech/topics/union-types.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Programming Language Type Systems](<https://devfeed.tech/topics/programming-language-type-systems.md>), [Data validation](<https://devfeed.tech/topics/data-validation.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>)

Tags: [arrays](<https://devfeed.tech/tags/arrays.md>), [collections](<https://devfeed.tech/tags/collections.md>), [generics](<https://devfeed.tech/tags/generics.md>), [json](<https://devfeed.tech/tags/json.md>), [phpdoc](<https://devfeed.tech/tags/phpdoc.md>), [symfony](<https://devfeed.tech/tags/symfony.md>), [types](<https://devfeed.tech/tags/types.md>), [union-types](<https://devfeed.tech/tags/union-types.md>)

### AI overview

Symfony 8.2 improves Serializer denormalization by resolving PHPDoc generic types from the property that holds a generic object, so nested values such as `Page<Product>` items become `Product` instances. This requires PropertyInfo's `PhpStanExtractor` and `phpstan/phpdoc-parser`; the target class name alone does not supply template types. It also denormalizes union-typed collection elements and throws when an element matches no union member or a key violates its key type. A JSON object supplied for `list<string>` still works in 8.2 but triggers a deprecation and will throw `NotNormalizableValueException` in 9.0; use a JSON array for a list, or an array type that permits meaningful keys. TypeInfo adds covariant-template support, `Type::map()` for replacing nested types, and `Type::getMismatches()` for paths and expected/actual types. Because mismatch reporting does more work, call it after `accepts()` returns false.

### Source excerpt

The Serializer component relies on the TypeInfo component to know the type of each property it denormalizes. Symfony 8.2 makes both components understand more of the types you already write in your PHPDoc, such as generics and arrays of union types, and makes...

## Generics in Kotlin

DevFeed: [Generics in Kotlin](<https://devfeed.tech/articles/generics-in-kotlin-39335.md>)

Original publisher: [Read original article](<https://kt.academy/article/kfde-generics>)

Published: 2024-03-18T00:01:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [class](<https://devfeed.tech/topics/class.md>), [function](<https://devfeed.tech/topics/function.md>), [interface](<https://devfeed.tech/topics/interface.md>)

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [functions](<https://devfeed.tech/tags/functions.md>), [generics](<https://devfeed.tech/tags/generics.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-compiler](<https://devfeed.tech/tags/kotlin-compiler.md>), [programming](<https://devfeed.tech/tags/programming.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This tutorial explains how generics work in Kotlin. It covers generic functions, classes, and interfaces, including type parameters, type arguments, explicit specification, compiler inference, and relationships between argument and result types.

### Source excerpt

The essence of how generics work in Kotlin.

## Understanding Flow

DevFeed: [Understanding Flow](<https://devfeed.tech/articles/understanding-flow-39242.md>)

Original publisher: [Read original article](<https://kt.academy/article/cc-understanding-flow>)

Published: 2023-05-29T00:00:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [interface](<https://devfeed.tech/topics/interface.md>), [function](<https://devfeed.tech/topics/function.md>), [object](<https://devfeed.tech/topics/object.md>), [Parameter](<https://devfeed.tech/topics/parameter.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>)

Tags: [coroutines](<https://devfeed.tech/tags/coroutines.md>), [function](<https://devfeed.tech/tags/function.md>), [interface](<https://devfeed.tech/tags/interface.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-coroutines](<https://devfeed.tech/tags/kotlin-coroutines.md>), [object](<https://devfeed.tech/tags/object.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This tutorial explains Kotlin Coroutines Flow by deriving its implementation from a suspending lambda, then introducing a functional interface, receiver, object expression, builder function, and generic type parameter. It concludes that the basic builder closely models how flow, emit, and collect are implemented.

### Source excerpt

We will explore how flow and its processing really works.

## Limitations of Generic Variance Modifiers in Java and Kotlin

DevFeed: [Limitations of Generic Variance Modifiers in Java and Kotlin](<https://devfeed.tech/articles/variance-modifiers-limitations-39219.md>)

Original publisher: [Read original article](<https://kt.academy/article/ak-variance-limitations>)

Published: 2023-02-20T00:15:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Generic Variance](<https://devfeed.tech/topics/generic-variance.md>), [Covariance](<https://devfeed.tech/topics/covariance.md>), [Contravariance](<https://devfeed.tech/topics/contravariance.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Java](<https://devfeed.tech/topics/java.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [runtime-errors](<https://devfeed.tech/tags/runtime-errors.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [variance](<https://devfeed.tech/tags/variance.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This tutorial explains how covariance and contravariance affect generic types in Java and Kotlin. It uses Java's covariant arrays to illustrate runtime type errors and describes why Kotlin restricts variance in public in-positions while allowing safe producer and read-only patterns.

### Source excerpt

What limitations generic variance modifiers introduce, and how can we ignore them.

## Kotlin Generic Variance Modifiers

DevFeed: [Kotlin Generic Variance Modifiers](<https://devfeed.tech/articles/kotlin-generic-variance-modifiers-39218.md>)

Original publisher: [Read original article](<https://kt.academy/article/ak-variance>)

Published: 2023-02-08T00:15:00Z

Content type: article

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Generic Variance](<https://devfeed.tech/topics/generic-variance.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Contravariance](<https://devfeed.tech/topics/contravariance.md>), [Covariance](<https://devfeed.tech/topics/covariance.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>)

Tags: [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [variance](<https://devfeed.tech/tags/variance.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This Kotlin tutorial explains invariant, covariant, and contravariant generic type parameters. It shows how variance affects subtype relationships and why covariance is suitable for read-only types, while mutable structures remain invariant for type safety.

### Source excerpt

What are out and in, and how do we use them without even knowing.

## Interfaces 101 : Heap Escape Ep. 2

DevFeed: [Interfaces 101 : Heap Escape Ep. 2](<https://devfeed.tech/articles/interfaces-101-heap-escape-ep-2-22215.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/02/interfaces-101-heap-escape.html>)

Published: 2023-02-08T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [interface](<https://devfeed.tech/topics/interface.md>), [Software](<https://devfeed.tech/topics/software.md>), [escape analysis](<https://devfeed.tech/topics/escape-analysis.md>), [inlining](<https://devfeed.tech/topics/inlining.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Type Argument](<https://devfeed.tech/topics/type-argument.md>), [data type](<https://devfeed.tech/topics/data-type.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [build](<https://devfeed.tech/tags/build.md>), [escape-heap](<https://devfeed.tech/tags/escape-heap.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [heap](<https://devfeed.tech/tags/heap.md>), [inlining](<https://devfeed.tech/tags/inlining.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [log-variables](<https://devfeed.tech/tags/log-variables.md>), [optimizations](<https://devfeed.tech/tags/optimizations.md>), [performance](<https://devfeed.tech/tags/performance.md>), [struct](<https://devfeed.tech/tags/struct.md>), [variable](<https://devfeed.tech/tags/variable.md>), [variables](<https://devfeed.tech/tags/variables.md>)

### AI overview

The episode examines how Go interfaces can affect performance by causing a function variable to escape to the heap. Using a weather struct and a function returning it, Miki demonstrates benchmarking, compiler optimization output, and Go build flags for identifying heap allocations. It also covers function comments that prevent compiler inlining and notes that Go logging functions accept interface arguments to make them more universal. The excerpt describes the episode's planned topics but does not provide benchmark results or quantify performance costs.

### Source excerpt

Introduction In episode 1, Miki had two functions that performed the similar operation, but returned different types. To refactor this, Miki rewrote both functions as a generic function that allowed him to specify the type to be returned during invocation. In some cases, the compiler may not recognise a type, thus, Miki gives a few pointers on manually telling a generic function which type to use. After demonstrating how to return different types with a generic function, Miki limited the types his generic function would accept with an interface.

## Generics Part 02: Underlying Types

DevFeed: [Generics Part 02: Underlying Types](<https://devfeed.tech/articles/generics-part-02-underlying-types-22168.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2020/08/generics-02-underlying-types.html>)

Published: 2020-08-18T00:00:00Z

Content type: article

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Programming Language Type Systems](<https://devfeed.tech/topics/programming-language-type-systems.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [data type](<https://devfeed.tech/topics/data-type.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [function](<https://devfeed.tech/tags/function.md>), [generics](<https://devfeed.tech/tags/generics.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [programming](<https://devfeed.tech/tags/programming.md>), [string](<https://devfeed.tech/tags/string.md>), [types](<https://devfeed.tech/tags/types.md>), [vector](<https://devfeed.tech/tags/vector.md>)

### AI overview

The post introduces Go's proposed generics syntax through a type whose underlying representation is a slice. It compares separate concrete vector types for integers and strings, each with a method that returns the highest-index value; when a vector is empty, the method returns the element type's zero value and an error. The excerpt explains the integer example's use and begins describing validation in the string example, but it cuts off before showing how the generic version is declared or evaluated.

### Source excerpt

Changes The draft is a living document which means these posts will need to change over time. This section documents when changes have taken place to this post. 21/08/20 : Moving forward with the generics design draft Series Index Generics Part 01: Basic Syntax Generics Part 02: Underlying Types Generics Part 03: Struct Types and Data Semantics Introduction In the previous post, I showed you how to write a generic function in Go using the proposed syntax from the generics draft document. I did this through the progression of writing different versions of the same function using concrete types, the empty interface, and then finally generics. I also provided information on why the new syntax was needed and how the compiler can simplify the calling of generic functions by inferring type information at the call site.

## Star-Projections and How They Work

DevFeed: [Star-Projections and How They Work](<https://devfeed.tech/articles/star-projections-and-how-they-work-25043.md>)

Original publisher: [Read original article](<https://typealias.com/guides/star-projections-and-how-they-work/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-04-05T00:00:00Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [Type Projection](<https://devfeed.tech/topics/type-projection.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Contravariance](<https://devfeed.tech/topics/contravariance.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [function](<https://devfeed.tech/tags/function.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [generics](<https://devfeed.tech/tags/generics.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [interface](<https://devfeed.tech/tags/interface.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [programming](<https://devfeed.tech/tags/programming.md>), [return](<https://devfeed.tech/tags/return.md>), [star-projection](<https://devfeed.tech/tags/star-projection.md>), [subtype](<https://devfeed.tech/tags/subtype.md>), [type](<https://devfeed.tech/tags/type.md>), [type-projection](<https://devfeed.tech/tags/type-projection.md>), [type-safe](<https://devfeed.tech/tags/type-safe.md>), [types](<https://devfeed.tech/tags/types.md>), [use-site-variance](<https://devfeed.tech/tags/use-site-variance.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

This excerpt introduces the final article in a Kotlin variance series, which applies two subtyping rules to functions that should accept every kind of a generic. It says the article will explore three ways to represent that broad supertype and explain why star-projections work, including how they affect function parameter and return types. The excerpt begins to set out the rules--subtypes must accept at least the types their supertypes declare and return at most the types those supertypes declare--but ends before showing the three approaches or completing the explanation.

### Source excerpt

Have you ever wondered how star-projections work? Or why they change your function parameter and return types? Or why it seems like sometimes you can actually get by without them? In the first article in this series, An Illustrated Guide to Covariance and Contravariance in Kotlin, we uncovered two simple, easy-to-understand rules that illuminate variance, and saw how they applied to regular class and interface inheritance in Kotlin. In the second article, The Ins and Outs of Generic Variance in Kotlin, we saw how those same two rules played out for generics, discovering what type projections are and how they work.

## The Ins and Outs of Generic Variance in Kotlin

DevFeed: [The Ins and Outs of Generic Variance in Kotlin](<https://devfeed.tech/articles/the-ins-and-outs-of-generic-variance-in-kotlin-25037.md>)

Original publisher: [Read original article](<https://typealias.com/guides/ins-and-outs-of-generic-variance/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-03-14T00:00:00Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Type Projection](<https://devfeed.tech/topics/type-projection.md>), [Contravariance](<https://devfeed.tech/topics/contravariance.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>)

Tags: [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [generics](<https://devfeed.tech/tags/generics.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [subtype](<https://devfeed.tech/tags/subtype.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

The excerpt uses two subtype rules to explain Kotlin generic variance: a subtype must accept at least the range of types its supertype declares and return at most that range. It applies these rules to a simple animal collection with operations for adding and retrieving items, starting with a desired relationship in which a collection of dogs should count as a collection of animals. The excerpt begins the covariance walkthrough but cuts off before explaining its conclusion or addressing type projections in detail.

### Source excerpt

Have you ever wondered why generic variance works like it does? Or why Kotlin won't let you use a type parameter as an argument when it's marked as out? Have you wondered why the compiler sometimes won't let you call a certain function on a generic? Yes, generics can seem mysterious, but with just two simple, easy-to-understand rules, we can reason our way through almost everything related to variance.

## Out-Projection

DevFeed: [Out-Projection](<https://devfeed.tech/articles/out-projection-25020.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/out-projection/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-02-05T00:00:00Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Type Projection](<https://devfeed.tech/topics/type-projection.md>), [Use-Site Variance](<https://devfeed.tech/topics/use-site-variance.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>)

Tags: [covariance](<https://devfeed.tech/tags/covariance.md>), [declaration-site-variance](<https://devfeed.tech/tags/declaration-site-variance.md>), [generic](<https://devfeed.tech/tags/generic.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [type-projection](<https://devfeed.tech/tags/type-projection.md>), [use-site-variance](<https://devfeed.tech/tags/use-site-variance.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

An out-projection adds covariance at the use site, allowing a generic type to accept a subtype even when the generic itself is not normally covariant. The tradeoff is that the projected type is read-only with respect to that type parameter: functions or setters that accept it cannot be used. This restriction prevents inserting a value that fits the projected type but not the actual underlying type, which could break type safety. The excerpt recommends out-projections when you need covariance for a generic you do not control and will not use those input operations; otherwise, consider declaration-site variance.

### Source excerpt

An out-projection is a kind of type projection that makes a generic covariant, but also causes any functions that accept the type parameter to be unusable in that context. You can think of it this way - In regular life, when some three-dimensional thing casts a shadow, that shadow is a two-dimensional projection of the original object - it's an incomplete representation of it. In the same way, an out-projection is a limited view of the original class.

## Type Argument

DevFeed: [Type Argument](<https://devfeed.tech/articles/type-argument-25024.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/type-argument/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-01-10T02:43:41Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [Type Argument](<https://devfeed.tech/topics/type-argument.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Use-Site Variance](<https://devfeed.tech/topics/use-site-variance.md>), [Type Projection](<https://devfeed.tech/topics/type-projection.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [generic](<https://devfeed.tech/tags/generic.md>), [invariant](<https://devfeed.tech/tags/invariant.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [type-argument](<https://devfeed.tech/tags/type-argument.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [type-projection](<https://devfeed.tech/tags/type-projection.md>), [values](<https://devfeed.tech/tags/values.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

A type argument is the concrete type a caller supplies for a generic's type parameter. It can be written in a variable declaration or on a function call or constructor invocation; a compiler may also infer it from context, which can produce a type different from the one intended, so an explicit argument may be needed. The excerpt also explains that generics are normally invariant: a generic over a subtype is not automatically a subtype of the same generic over its supertype. A variance annotation can create a type projection that accepts different subtype arguments when the code only reads values and does not set them. Type arguments are the supplied types; type parameters are the placeholders.

### Source excerpt

A type argument is a specific type, specified by the calling code, that a generic will use in place of a type parameter. If your generic were a light fixture, then the light bulb that's screwed into that light fixture is the type argument. Just as different kinds of light bulbs can be used in a light fixture's socket, different call sites can each specify a different type argument to use in instances of a generic.

## Type Parameter

DevFeed: [Type Parameter](<https://devfeed.tech/articles/type-parameter-25027.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/type-parameter/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-01-04T03:23:40Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [Type Argument](<https://devfeed.tech/topics/type-argument.md>), [interface](<https://devfeed.tech/topics/interface.md>), [Reified Type Parameter](<https://devfeed.tech/topics/reified-type-parameter.md>)

Tags: [annotation](<https://devfeed.tech/tags/annotation.md>), [class](<https://devfeed.tech/tags/class.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [constraint](<https://devfeed.tech/tags/constraint.md>), [function](<https://devfeed.tech/tags/function.md>), [generic](<https://devfeed.tech/tags/generic.md>), [interface](<https://devfeed.tech/tags/interface.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [reification](<https://devfeed.tech/tags/reification.md>), [reified-type-parameter](<https://devfeed.tech/tags/reified-type-parameter.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

A type parameter is a placeholder for a type chosen by code that uses a generic. It can be declared and referenced in multiple places within a generic function, class, or interface; classes, functions, extension properties, and interfaces can all be generic. Names are conventionally single uppercase letters. Constraints limit which types callers may supply. Generic classes and interfaces do not support subtyping by default, but variance annotations can introduce it while limiting how the type parameter can be used. Reified type parameters can be used to check an object against the parameter's type or obtain a class reference.

### Source excerpt

A type parameter is a placeholder for an actual type, which gets specified by the code that's using the generic. If you imagine your generic as a light fixture, the type parameter would be the socket where the light bulb goes. Just as you can choose from a variety of different light bulbs to put into that socket, the calling code can choose from a variety of different types to pass to a generic.

## Invariance

DevFeed: [Invariance](<https://devfeed.tech/articles/invariance-25018.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/invariance/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-11-28T03:03:36Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [Use-Site Variance](<https://devfeed.tech/topics/use-site-variance.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Contravariance](<https://devfeed.tech/topics/contravariance.md>)

Tags: [generic](<https://devfeed.tech/tags/generic.md>), [generics](<https://devfeed.tech/tags/generics.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [invariance](<https://devfeed.tech/tags/invariance.md>), [invariant](<https://devfeed.tech/tags/invariant.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [subtype](<https://devfeed.tech/tags/subtype.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

Invariance means that a generic type does not subtype another version of itself even when their component types are related: neither Foo<Child> nor Foo<Parent> is a subtype of the other in the example. Kotlin and Java generics are invariant by default when no variance annotation is specified. This allows a type parameter to be used both as a function argument and as a return value. A class can also have different variance for different parameters; the excerpt gives an example with covariant, contravariant, and invariant parameters. For inherited members, properties declared with var are described as invariant because their type is both read through a getter and written through a setter. The excerpt begins discussing function argument and return types but is truncated before completing those rules.

### Source excerpt

When dealing with simple classes, subtyping is straightforward. But once we start talking about generics, subtyping rules become more complicated, and we describe the subtyping rules in terms of variance. What is Invariance? Invariance describes a relationship between two sets of types where the complex types do not subtype at all, despite any subtyping that might exist for the component types. Does that sound confusing?1 Thankfully, it's way more easily demonstrated than defined, so let's look at an example.

## Contravariance

DevFeed: [Contravariance](<https://devfeed.tech/articles/contravariance-25010.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/contravariance/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-11-17T01:58:28Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Contravariance](<https://devfeed.tech/topics/contravariance.md>), [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Inheritance](<https://devfeed.tech/topics/inheritance.md>), [subclass](<https://devfeed.tech/topics/subclass.md>), [class](<https://devfeed.tech/topics/class.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [contravariance](<https://devfeed.tech/tags/contravariance.md>), [function](<https://devfeed.tech/tags/function.md>), [functions](<https://devfeed.tech/tags/functions.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generics](<https://devfeed.tech/tags/generics.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [invariant](<https://devfeed.tech/tags/invariant.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [subtype](<https://devfeed.tech/tags/subtype.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [types](<https://devfeed.tech/tags/types.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

Contravariance reverses the subtype relationship of a generic type's parameter: if Dog is a subtype of Animal, a contravariant generic for Animal can be used where one for Dog is expected. The excerpt says to mark the type parameter with the language's contravariance annotation; without it, the generic is invariant. The tradeoff is that an instance cannot return a result of type T, since it promises only to accept values of that type. The excerpt also notes that covariant return types are allowed in many languages, including Java and Kotlin, while most languages do not allow contravariant method argument types.

### Source excerpt

Most of the time, subtyping is intuitive. Object-oriented programmers are used to the concept of inheritance, where one class specializes another, and we're familiar with the idea of passing, say, a Dog object where a function expects an Animal. Once you start working with generics, though, there are some fascinating twists that flip our typical understanding of subtyping on its head. What is Contravariance? Contravariance describes a relationship between two sets of types where they subtype in opposite directions.

## Getting Real with Kotlin's Reified Type Parameters

DevFeed: [Getting Real with Kotlin's Reified Type Parameters](<https://devfeed.tech/articles/getting-real-with-kotlin-s-reified-type-parameters-25034.md>)

Original publisher: [Read original article](<https://typealias.com/guides/getting-real-with-reified-type-parameters/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-10-12T02:26:46Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Reified Type Parameter](<https://devfeed.tech/topics/reified-type-parameter.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [generics](<https://devfeed.tech/tags/generics.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [reification](<https://devfeed.tech/tags/reification.md>), [reified-type-parameter](<https://devfeed.tech/tags/reified-type-parameter.md>), [type](<https://devfeed.tech/tags/type.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [type-parameters](<https://devfeed.tech/tags/type-parameters.md>)

### AI overview

Kotlin reified type parameters let an inline function use its actual type argument at the call site, enabling runtime type comparisons and access to Class objects--operations that ordinary type parameters generally cannot support because they are erased. The excerpt says reified parameters are available only on inline functions (and extension properties backed by a function); inlining makes the concrete type known where the function is called. The article also notes that some uses of type parameters are inherently unsuitable, while other cases may have reflection workarounds. The excerpt ends as it introduces a favored use case, so it does not establish what that use case is.

### Source excerpt

Let's think for a moment about everything that you can do with a class name in Kotlin - think of all the cases where you literally type out the name of a class in your source code. I came up with the following 15 cases, but I probably missed a few. Get your scrolling finger ready, here we go... 1 - Define a member property: private val thing: Thing 2 - Function argument: fun doSomething(thing: Thing) {} 3 - Type argument: val list = listOf<Thing>() 4 - Type parameter constraint: class Item<T : Thing> 5 - Cast to the type: something as Thing 6 - Define the class: open class Thing {} 7 - Extend the class: class Other : Thing() 8 - Import the class: import com.

## Type Parameter Constraint

DevFeed: [Type Parameter Constraint](<https://devfeed.tech/articles/type-parameter-constraint-25025.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/type-parameter-constraint/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-30T01:54:04Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Type Argument](<https://devfeed.tech/topics/type-argument.md>), [Parameter](<https://devfeed.tech/topics/parameter.md>)

Tags: [constraint](<https://devfeed.tech/tags/constraint.md>), [generic](<https://devfeed.tech/tags/generic.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

Kotlin type parameter constraints restrict accepted type arguments to an upper bound while preserving access to that type's functions and properties. Constraints can be written in the type parameter declaration or, in a more verbose form, after the return type. Both forms support constraints on multiple parameters; the verbose form also allows one parameter to have multiple constraints, so a type must satisfy each bound.

### Source excerpt

Overview Type parameter constraints allow you to limit the types that can be accepted as a type argument to an upper bound, giving you the ability to invoke functions and properties on an object while preserving the type. If that sounds confusing, go check out the guide, When to Use Type Parameter Constraints, which walks through the use cases in more detail. In this article, we're going to look at the variety of ways that you can create a type parameter constraint in Kotlin.

## Generic Function

DevFeed: [Generic Function](<https://devfeed.tech/articles/generic-function-25015.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/generic-function/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-21T02:07:39Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [generic programming](<https://devfeed.tech/topics/generic-programming.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>), [Type Argument](<https://devfeed.tech/topics/type-argument.md>)

Tags: [function](<https://devfeed.tech/tags/function.md>), [functions](<https://devfeed.tech/tags/functions.md>), [generic](<https://devfeed.tech/tags/generic.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-generic-function](<https://devfeed.tech/tags/kotlin-generic-function.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [programming](<https://devfeed.tech/tags/programming.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [type-safety](<https://devfeed.tech/tags/type-safety.md>)

### AI overview

Kotlin generic functions use a type parameter declared before the function name, allowing the argument and return types to stay linked. The `middleItem` example takes a `List<T>` and returns a `T`; different call sites can use different item types while preserving the result type without casting. The excerpt says Kotlin's syntax differs slightly from Java in where the type parameter and return type are declared. An abstract argument or return type can instead suit a function that only needs polymorphic behavior, but callers then need casts when recovering a more specific type.

### Source excerpt

Overview Generic functions are functions that accept a type parameter, which allows different call sites to pass different types, without sacrificing type safety. Yeah, that's a mouthful, so let's just take a look at an example. Example Definition Here's a Kotlin generic function that returns the middle-most item out of a List: fun <T> middleItem(list: List<T>): T = list[list.size / 2] This example specifies: A type parameter of type T. This type parameter declaration goes before the name of the function, and it's written here as <T>.