# generics

Generics let types serve as parameters when defining reusable classes, interfaces, and methods, enabling type-safe code for different data 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.

## Inside Go -- How It Really Works: Series Kickoff

DevFeed: [Inside Go -- How It Really Works: Series Kickoff](<https://devfeed.tech/articles/inside-go-how-it-really-works-series-kickoff-39762.md>)

Original publisher: [Read original article](<https://furkankolcu.com/post/inside-go-how-it-really-works-series-kickoff>)

Author: Furkan Kolcu

Published: 2025-09-11T10:16:52Z

Content type: article

Language: en

Sources: [Furkan Kolcu - Software Engineer Blog](<https://devfeed.tech/sources/furkan-kolcu-software-engineer-blog.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Code](<https://devfeed.tech/topics/code.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [escape analysis](<https://devfeed.tech/topics/escape-analysis.md>), [generics](<https://devfeed.tech/topics/generics.md>), [modules](<https://devfeed.tech/topics/modules.md>), [reproducible builds](<https://devfeed.tech/topics/reproducible-builds.md>)

Tags: [compilation](<https://devfeed.tech/tags/compilation.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [deep-dive](<https://devfeed.tech/tags/deep-dive.md>), [generics](<https://devfeed.tech/tags/generics.md>), [go](<https://devfeed.tech/tags/go.md>), [go-compiler](<https://devfeed.tech/tags/go-compiler.md>), [go-concurrency](<https://devfeed.tech/tags/go-concurrency.md>), [go-performance](<https://devfeed.tech/tags/go-performance.md>), [go-runtime](<https://devfeed.tech/tags/go-runtime.md>), [golang](<https://devfeed.tech/tags/golang.md>), [how-go-works](<https://devfeed.tech/tags/how-go-works.md>), [inside-go](<https://devfeed.tech/tags/inside-go.md>), [internals](<https://devfeed.tech/tags/internals.md>), [memory-management](<https://devfeed.tech/tags/memory-management.md>), [performance](<https://devfeed.tech/tags/performance.md>), [technology](<https://devfeed.tech/tags/technology.md>)

### AI overview

This article launches a technical series about how Go works internally. The planned installments cover compilation, memory management, garbage collection, concurrency, the runtime, performance tuning, interfaces, generics, modules, and reproducible builds, with code examples and runtime experiments.

### Source excerpt

A deep-dive series into Go's internals. From compilation to memory management, concurrency, and performance tuning, each part unpacks how Go operates under the hood with clear explanations and real-life code examples.

## How to use generics to avoid duplications and make your code better

DevFeed: [How to use generics to avoid duplications and make your code better](<https://devfeed.tech/articles/how-to-use-generics-to-avoid-duplications-and-make-your-code-better-32291.md>)

Original publisher: [Read original article](<https://domenicoluciani.com/2025/04/11/how-to-use-generics-to-avoid-duplications-and-make-your-code-better.html>)

Author: Domenico Luciani

Published: 2025-04-10T22:00:00Z

Content type: tutorial

Language: en

Sources: [Domenico Luciani](<https://devfeed.tech/sources/domenico-luciani.md>)

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [JSON:API](<https://devfeed.tech/topics/json-api.md>), [factory function](<https://devfeed.tech/topics/factory-function.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [create](<https://devfeed.tech/tags/create.md>), [generics](<https://devfeed.tech/tags/generics.md>), [go](<https://devfeed.tech/tags/go.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [like](<https://devfeed.tech/tags/like.md>), [refactor](<https://devfeed.tech/tags/refactor.md>)

### AI overview

A Go tutorial explains how generics can reduce duplicated method implementations when multiple response structs must satisfy the same interfaces. It demonstrates applying a reusable generic response to JSON:API-formatted responses and adding a factory function for readability.

### Source excerpt

I recently worked on a project that had a lot of code duplication due to repeated implementations of the same interfaces. I quickly realized it was a great opportunity to refactor...

## Resisting the Urge to Document Everything Everywhere

DevFeed: [Resisting the Urge to Document Everything Everywhere](<https://devfeed.tech/articles/resisting-the-urge-to-document-everything-everywhere-28958.md>)

Original publisher: [Read original article](<https://blog.jooq.org/resisting-the-urge-to-document-everything-everywhere/>)

Author: lukaseder

Published: 2025-02-28T10:39:07Z

Content type: opinion

Language: en

Sources: [jOOQ](<https://devfeed.tech/sources/jooq.md>)

Topics: [jooq](<https://devfeed.tech/topics/jooq.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [generics](<https://devfeed.tech/topics/generics.md>)

Tags: [caveat](<https://devfeed.tech/tags/caveat.md>), [documentation](<https://devfeed.tech/tags/documentation.md>), [generics](<https://devfeed.tech/tags/generics.md>), [jooq](<https://devfeed.tech/tags/jooq.md>), [jooq-development](<https://devfeed.tech/tags/jooq-development.md>), [quirk](<https://devfeed.tech/tags/quirk.md>), [sql](<https://devfeed.tech/tags/sql.md>), [stack-overflow](<https://devfeed.tech/tags/stack-overflow.md>), [xyproblem](<https://devfeed.tech/tags/xyproblem.md>)

### AI overview

The article argues that product teams should resist documenting every workaround alongside the feature that exposed a user's problem. Using jOOQ as an example, it explains that unrelated features can be difficult to discover even when one helps address a quirk or limitation in another.

### Source excerpt

Every product manager knows this situation: This is such a common pattern, and while it's perfectly understandable for such a user to request this, it is so terribly wrong to give in to this user's request. Why is it wrong? The features are unrelated Most of the time, the two features X1 and X2 are ... Continue reading Resisting the Urge to Document Everything Everywhere ->

## Making sense of TypeScript generics

DevFeed: [Making sense of TypeScript generics](<https://devfeed.tech/articles/making-sense-of-typescript-generics-20098.md>)

Original publisher: [Read original article](<https://medium.com/jobteaser-dev-team/making-sense-of-typescript-generics-6b830e66eeff?source=rss----bd77d16a0035---4>)

Author: Clément Gateaud

Published: 2024-07-04T16:12:05Z

Content type: tutorial

Language: en

Sources: [JobTeaser](<https://devfeed.tech/sources/jobteaser.md>)

Topics: [TypeScript](<https://devfeed.tech/topics/typescript.md>), [generics](<https://devfeed.tech/topics/generics.md>), [Code](<https://devfeed.tech/topics/code.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [development](<https://devfeed.tech/tags/development.md>), [errors](<https://devfeed.tech/tags/errors.md>), [generics](<https://devfeed.tech/tags/generics.md>), [generics-in-typescript](<https://devfeed.tech/tags/generics-in-typescript.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [type-safety](<https://devfeed.tech/tags/type-safety.md>), [types](<https://devfeed.tech/tags/types.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [web-development](<https://devfeed.tech/tags/web-development.md>)

### AI overview

This tutorial explains TypeScript generics through a simple JavaScript function that returns the first element of an array. It contrasts generics with using any, explicit lists of possible types, and type assertions, emphasizing improved type inference and type safety.

### Source excerpt

TypeScript significantly improved JavaScript development with enhanced code reliability and maintainability, ensuring fewer runtime errors and greater productivity for developers. But when you start working with it, the syntax can sometimes feel overwhelming. One of the most intimidating features in TypeScript is "generics". Look at the example below 🤯 aren't you afraid ? Types declarations from @tanstack/react-query (library) that can feel overwhelming But don't worry, we will go step by step and once you understand generics, you'll see how powerful they are. The best any alternative Imagine this very simple JavaScript function that returns the first element of an array. (I agree, this function is not very useful, but it's for the sake of explanation). How could we type it? 🤔 What would be the type of the array? Well, in this function it could be an array of anything (a string, a number, an object). So it could be tempting to type it like this, using the type whose name must not be spoken: any 😱 But this is very bad typing. Why? Because TypeScript won't be able to properly infer the return type of this function. So maybe we could specify all the different types it could be? Not a good idea. First, because it would force you to maintain a huge list of all the possible types for this function. But more importantly, because it doesn't solve our inference issue. TypeScript is not smart enough to guess the type when calling the function. So maybe we could use casting with as to help TypeScript? But that's cheating! With this type assertion, you are telling TypeScript: "Stop type checking and trust me, I know what I'm doing". This weakens type safety which is the core purpose of using TypeScript. Don't do that! There's a way safer and cleaner way to type this. Guess how it's named? ✨ Generics✨ Introducing generics Let's keep our previous example. What we want to tell our function is: "You will take as a parameter an array of SOMETHING, and you will return a SOMETHING ele

## The problem of union types for type systems

DevFeed: [The problem of union types for type systems](<https://devfeed.tech/articles/the-problem-of-union-types-for-type-systems-39390.md>)

Original publisher: [Read original article](<https://kt.academy/article/union-types-into>)

Published: 2024-06-10T00:00:00Z

Content type: opinion

Language: en

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

Topics: [union types](<https://devfeed.tech/topics/union-types.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [subtype](<https://devfeed.tech/topics/subtype.md>), [generics](<https://devfeed.tech/topics/generics.md>)

Tags: [generics](<https://devfeed.tech/tags/generics.md>), [inference](<https://devfeed.tech/tags/inference.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-languages](<https://devfeed.tech/tags/programming-languages.md>), [smart-cast](<https://devfeed.tech/tags/smart-cast.md>), [static](<https://devfeed.tech/tags/static.md>), [subtype](<https://devfeed.tech/tags/subtype.md>), [type](<https://devfeed.tech/tags/type.md>), [types](<https://devfeed.tech/tags/types.md>), [union](<https://devfeed.tech/tags/union.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This article explains why general union types are difficult to add to Kotlin and other statically typed systems. It discusses ambiguity in subtype relationships and generic type inference, including the claim that inference is NP-hard, then describes Kotlin's proposed limited use of union types for representing errors through rich errors.

### Source excerpt

Why union types are not such a good idea for static type systems.

## Generic Variance

DevFeed: [Generic Variance](<https://devfeed.tech/articles/generic-variance-25066.md>)

Original publisher: [Read original article](<https://typealias.com/start/kotlin-variance/>)

Author: author@typealias.com (Dave Leeds)

Published: 2024-04-23T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [advanced-kotlin-concepts](<https://devfeed.tech/tags/advanced-kotlin-concepts.md>), [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [extend](<https://devfeed.tech/tags/extend.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [generics](<https://devfeed.tech/tags/generics.md>), [implement](<https://devfeed.tech/tags/implement.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-generics](<https://devfeed.tech/tags/kotlin-generics.md>), [kotlin-type-safety](<https://devfeed.tech/tags/kotlin-type-safety.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-language-type-systems](<https://devfeed.tech/tags/programming-language-type-systems.md>), [software-development](<https://devfeed.tech/tags/software-development.md>), [subtyping-in-kotlin](<https://devfeed.tech/tags/subtyping-in-kotlin.md>), [type-parameters](<https://devfeed.tech/tags/type-parameters.md>)

### AI overview

A tutorial on variance in Kotlin generic types. It explains how covariance and contravariance affect subtype relationships between parameterized types, using examples to show when one generic type can substitute for another.

### Source excerpt

We've seen how we can implement interfaces and extend classes to create subtypes. However, with generic types, we sometimes want to create a subtype based on the type arguments instead of the base types. Kotlin gives us a few different tools to achieve this, and in this chapter we'll learn all about them. In order to understand how this is possible, we'll first need to understand the principles of variance. Then, we'll look at three simple rules that explain when one parameterized type can be the subtype of another.

## Generics

DevFeed: [Generics](<https://devfeed.tech/articles/generics-25057.md>)

Original publisher: [Read original article](<https://typealias.com/start/kotlin-generics/>)

Author: author@typealias.com (Dave Leeds)

Published: 2024-03-26T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [collections](<https://devfeed.tech/tags/collections.md>), [enum-class](<https://devfeed.tech/tags/enum-class.md>), [function](<https://devfeed.tech/tags/function.md>), [generics](<https://devfeed.tech/tags/generics.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-generic-function](<https://devfeed.tech/tags/kotlin-generic-function.md>), [kotlin-generics](<https://devfeed.tech/tags/kotlin-generics.md>), [kotlin-parameterized-types](<https://devfeed.tech/tags/kotlin-parameterized-types.md>), [kotlin-type-argument](<https://devfeed.tech/tags/kotlin-type-argument.md>), [kotlin-type-erasure](<https://devfeed.tech/tags/kotlin-type-erasure.md>), [kotlin-type-parameter](<https://devfeed.tech/tags/kotlin-type-parameter.md>), [kotlin-type-parameter-constraint](<https://devfeed.tech/tags/kotlin-type-parameter-constraint.md>), [kotlin-type-safety](<https://devfeed.tech/tags/kotlin-type-safety.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [list](<https://devfeed.tech/tags/list.md>), [map](<https://devfeed.tech/tags/map.md>), [pair](<https://devfeed.tech/tags/pair.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

A tutorial introducing Kotlin generics through collection types such as List, Pair, and Map, using a beverage-menu example with classes and an enum class.

### Source excerpt

All the way back in Chapter 8, when we introduced collections, we saw our first generic type: List<String> ... then we saw more generics in Chapter 9 when we looked at the Pair and Map classes. In order to stay focused on learning about collection types, we glossed over the details about these classes. Well, we've put off learning about them for long enough! It's finally time for us to gain a full understanding of generics, so buckle up!

## 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: [generics](<https://devfeed.tech/topics/generics.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [classes](<https://devfeed.tech/topics/classes.md>), [function](<https://devfeed.tech/topics/function.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [kotlin compiler](<https://devfeed.tech/topics/kotlin-compiler.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.

## Sealed Generics and SKIE - Paul Hawke

DevFeed: [Sealed Generics and SKIE - Paul Hawke](<https://devfeed.tech/articles/sealed-generics-and-skie-paul-hawke-38314.md>)

Original publisher: [Read original article](<https://touchlab.co/sealed-generics-and-skie>)

Published: 2023-10-10T00:00:00Z

Content type: tutorial

Language: en

Sources: [Touchlab | Enterprise Mobile Innovation & Development](<https://devfeed.tech/sources/touchlab-enterprise-mobile-innovation-development.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [generics](<https://devfeed.tech/topics/generics.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [classes](<https://devfeed.tech/topics/classes.md>), [Xcode](<https://devfeed.tech/topics/xcode.md>)

Tags: [apis](<https://devfeed.tech/tags/apis.md>), [classes](<https://devfeed.tech/tags/classes.md>), [generics](<https://devfeed.tech/tags/generics.md>), [kmp](<https://devfeed.tech/tags/kmp.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform](<https://devfeed.tech/tags/kotlin-multiplatform.md>), [sealed](<https://devfeed.tech/tags/sealed.md>), [sealed-classes](<https://devfeed.tech/tags/sealed-classes.md>), [skie](<https://devfeed.tech/tags/skie.md>), [swift](<https://devfeed.tech/tags/swift.md>), [type](<https://devfeed.tech/tags/type.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

### AI overview

This tutorial explores how SKIE improves the use of Kotlin sealed classes with generics when exposing Kotlin Multiplatform code to Swift. It discusses type discovery in Xcode, Swift interoperability, and concurrency-related code paths.

### Source excerpt

Sealed Classes and Generics are both very useful for Kotlin APIs, and very painful with KMP and Swift. One of SKIE's lesser known benefits is the restoration of using Sealed Classes with generics, along with proper type discovery in Xcode.

## Polymorphic, Recursive Interfaces Using Go Generics

DevFeed: [Polymorphic, Recursive Interfaces Using Go Generics](<https://devfeed.tech/articles/polymorphic-recursive-interfaces-using-go-generics-29342.md>)

Original publisher: [Read original article](<https://multithreaded.stitchfix.com/blog/2023/02/01/go-polymorphic-interfaces/>)

Published: 2023-02-01T09:00:00Z

Content type: tutorial

Language: en

Sources: [Stitch Fix](<https://devfeed.tech/sources/stitch-fix.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [generics](<https://devfeed.tech/topics/generics.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [generics](<https://devfeed.tech/tags/generics.md>), [go](<https://devfeed.tech/tags/go.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>)

### AI overview

The article explains how Go generics enable polymorphic interfaces whose methods return the concrete receiver type, using logger implementations as an example. It also discusses the limitations of Go's type inference, which can require explicit type parameters when using these interfaces.

### Source excerpt

I did a bit of experimenting over the weekend in an attempt to figure out how to write an interface that abstracted over methods whose return type was identical to the receiver's type. This is frequently a thing that one wants to do when abstracting over self-cloning objects, or things that implement the Builder pattern. For example, suppose we have a struct through which we log stuff: type StdoutLogger struct { out ioutil.Writer outMu sync.Mutex fields map[string]interface{} } func (n *StdoutLogger) WithFields(fields map[string]interface{}) (out *StdoutLogger) { for k, v := range fields { out.fields[k] = v } return } func (n *StdoutLogger) Infof(format string, args ...interface{}) { n.outMu.Lock() defer n.outMu.Unlock() s := fmt.Sprintf(format, args...) if len(n.fields) > 0 { s += " " } for k, v := range n.fields { s += fmt.Sprintf("%s=%+v", k, v) } n.out.Write([]byte(s)) } ...and we've got some other struct that we use during test which ignores all requests to log stuff: type NoopLogger struct {} func (n *NoopLogger) WithFields(fields map[string]interface{}) *NoopLogger { return n } func (n NoopLogger) Infof(format string, args ...interface{}) { return } Before Go Generics Before the Go "generics" feature was released, defining an interface that abstracted over both structs was not possible (link). For example, if we had a pre-generics interface that looked like: type Logger interface { WithFields(fields map[string]interface{}) Logger Infof(format string, args ...interface{}) } ...there would be no way to satisfy it with types that had these signatures: func (n *NoopLogger) WithFields(fields map[string]interface{}) *NoopLogger func (n *StdoutLogger) WithFields(fields map[string]interface{}) *StdoutLogger ...because of the different return types of each struct's WithFields method. Polymorphic Interfaces Now that generics have landed, we can define an interface that abstracts over both of these structs: type Logger[T any] interface { WithFields(fields map[string]interface

## Making reusable composables using Generics

DevFeed: [Making reusable composables using Generics](<https://devfeed.tech/articles/making-reusable-composables-using-generics-22651.md>)

Original publisher: [Read original article](<https://www.valueof.io/blog/compose-composable-function-generics>)

Author: James Shvarts

Published: 2022-04-29T20:02:08Z

Content type: tutorial

Language: en

Sources: [Android Blog - Mobile Dev Notes](<https://devfeed.tech/sources/android-blog-mobile-dev-notes.md>)

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Compose](<https://devfeed.tech/topics/compose.md>), [Java](<https://devfeed.tech/topics/java.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [component](<https://devfeed.tech/tags/component.md>), [compose](<https://devfeed.tech/tags/compose.md>), [dialog](<https://devfeed.tech/tags/dialog.md>), [generics](<https://devfeed.tech/tags/generics.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

This tutorial shows how to use Java Generics with Jetpack Compose to build reusable composable components that support different model objects. It demonstrates a shared delete-confirmation dialog, call sites, optional properties, and state handling in a ViewModel.

### Source excerpt

Using Java Generics to create reusable shared components in Compose

## PhpStorm 2021.2: дженерики, перечисления, array shapes, новые инспекции и рефакторинги

DevFeed: [PhpStorm 2021.2: дженерики, перечисления, array shapes, новые инспекции и рефакторинги](<https://devfeed.tech/articles/phpstorm-2021-2-array-shapes-23928.md>)

Original publisher: [Read original article](<https://habr.com/ru/companies/JetBrains/articles/571962/>)

Author: pronskiy (JetBrains)

Published: 2021-08-09T12:07:54Z

Content type: release

Language: ru

Sources: [JetBrains RU](<https://devfeed.tech/sources/jetbrains-ru.md>)

Topics: [phpstorm](<https://devfeed.tech/topics/phpstorm.md>), [PHP](<https://devfeed.tech/topics/php.md>), [generics](<https://devfeed.tech/topics/generics.md>), [ide](<https://devfeed.tech/topics/ide.md>)

Tags: [enums](<https://devfeed.tech/tags/enums.md>), [generics](<https://devfeed.tech/tags/generics.md>), [ide](<https://devfeed.tech/tags/ide.md>), [php](<https://devfeed.tech/tags/php.md>), [php-8-1](<https://devfeed.tech/tags/php-8-1.md>), [phpdoc](<https://devfeed.tech/tags/phpdoc.md>), [phpstorm](<https://devfeed.tech/tags/phpstorm.md>), [tag-831b63de9433](<https://devfeed.tech/tags/tag-831b63de9433.md>), [tag-e605ecb2bfdd](<https://devfeed.tech/tags/tag-e605ecb2bfdd.md>), [toolbox-app](<https://devfeed.tech/tags/toolbox-app.md>)

### AI overview

JetBrains details the PhpStorm 2021.2 release, including new PHP IDE actions, version-control improvements, and support for several generic-programming scenarios through PHPDoc annotations. The article also covers collections, factory patterns, and planned future enhancements.

### Source excerpt

Вышел второй мажорный релиз PhpStorm в этом году. Под катом подробный разбор всех изменений и новых возможностей с кучей гифок.

## Using @JvmSuppressWildcards to resolve Kotlin and Java generic type issues

DevFeed: [Using @JvmSuppressWildcards to resolve Kotlin and Java generic type issues](<https://devfeed.tech/articles/jvmsuppresswildcards-the-secret-sauce-to-your-sandwich-style-generics-25906.md>)

Original publisher: [Read original article](<https://chao2zhang.medium.com/jvmsuppresswildcards-the-secret-sauce-to-your-sandwich-style-generics-b0093aa5979d?source=rss-d19045640fe------2>)

Author: Chao Zhang

Published: 2021-02-23T16:01:15Z

Content type: tutorial

Language: en

Sources: [Stories by Chao Zhang on Medium](<https://devfeed.tech/sources/stories-by-chao-zhang-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [generics](<https://devfeed.tech/topics/generics.md>), [Java](<https://devfeed.tech/topics/java.md>), [Android](<https://devfeed.tech/topics/android.md>), [Dagger](<https://devfeed.tech/topics/dagger.md>), [recyclerview](<https://devfeed.tech/topics/recyclerview.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [compilation-error](<https://devfeed.tech/tags/compilation-error.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [generics](<https://devfeed.tech/tags/generics.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-generics](<https://devfeed.tech/tags/kotlin-generics.md>), [recyclerview](<https://devfeed.tech/tags/recyclerview.md>)

### AI overview

This tutorial explains how Kotlin generics interact with Java in mixed Kotlin-Java codebases, including Android applications and Dagger-based dependencies. It shows how the @JvmSuppressWildcards annotation can resolve compilation and type-inference problems when Kotlin generic APIs are consumed by Java code.

### Source excerpt

Photo: amirali mirhashemian from Unsplash If generic types are exposed in Kotlin API, consider @JvmSuppressWildcards so that your Java consumer can compile successfully. Kotlin generics are different from (in my opinion, smarter than) Java generics. Kotlin generics has declaration-site variance and type projections, which are officially documented here. Generics is a gigantic topic itself. My usual practice is to leverage IDE warnings and compiler error messages to fix my code since they usually contain the necessary information to show you where you did wrong. However, as we are Kotlinizing our codebase from Java to Kotlin, it is possible to have a sandwich-style code dependency that mixes Java code and Kotlin code. In such cases, when dealing with generics, your compiler and IDE may not be smart enough to help you fix those issues. What is sandwich-style code dependency?🥪 Sandwich-style Kotlin conversion At a certain time during your Java to Kotlin conversion, there could be some Java code depending on Kotlin code, which in turn depends on Java code. A typical example on Android is that your app code in Java depending on your library in Kotlin, which depends on Android SDK in Java. Even if your app code is written purely in Kotlin, the sandwich might still exist: The Java-based annotation processing Dagger, depends on your app code in Kotlin, which depends on Android SDK in Java. Now let's look at how the secret sauce @JvmSuppressWildcards can help us by making our generic sandwich tasty. Sandwich: List<Object> in RecyclerView methodshttps://medium.com/media/87fd0c63db2b9c82af2b241bf61cef31/href With the code above, the following compilation error is observed: MyChildAdapter.java:13: error: name clash: onBindViewHolder(MyViewHolder,int,List<Object>) in MyChildAdapter overrides a method whose erasure is the same as another method, yet neither overrides the other The error message leads us to think that we need to change our type here: Change the Kotlin generic para

## Traits: Rust's unifying concept

DevFeed: [Traits: Rust's unifying concept](<https://devfeed.tech/articles/traits-rust-s-unifying-concept-35475.md>)

Original publisher: [Read original article](<https://darkcoding.net/software/traits-rusts-unifying-concept/>)

Author: Graham King

Published: 2021-01-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [Graham King](<https://devfeed.tech/sources/graham-king.md>)

Topics: [Rust](<https://devfeed.tech/topics/rust.md>), [generics](<https://devfeed.tech/topics/generics.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [Haskell](<https://devfeed.tech/topics/haskell.md>)

Tags: [concepts](<https://devfeed.tech/tags/concepts.md>), [generics](<https://devfeed.tech/tags/generics.md>), [implement](<https://devfeed.tech/tags/implement.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [rust](<https://devfeed.tech/tags/rust.md>), [software](<https://devfeed.tech/tags/software.md>)

### AI overview

Rust traits unify several programming concepts, including interfaces, abstract classes, mix-ins, operator overloading, and generic constraints. The article explains how these uses are implemented through traits and discusses trait ownership rules for implementations across packages.

### Source excerpt

Rust's traits are a single concept that unifies interfaces, abstract classes, mix-ins, operator overloading, contraints on generics, and more.

## Parameters and Arguments: An Easy Way to Remember the Difference

DevFeed: [Parameters and Arguments: An Easy Way to Remember the Difference](<https://devfeed.tech/articles/parameters-and-arguments-an-easy-way-to-remember-the-difference-25042.md>)

Original publisher: [Read original article](<https://typealias.com/guides/parameters-arguments/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-06-27T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [argument](<https://devfeed.tech/tags/argument.md>), [article](<https://devfeed.tech/tags/article.md>), [generics](<https://devfeed.tech/tags/generics.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [mnemonic](<https://devfeed.tech/tags/mnemonic.md>), [parameter](<https://devfeed.tech/tags/parameter.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>), [types](<https://devfeed.tech/tags/types.md>)

### AI overview

A tutorial explaining the difference between parameters and arguments in functions and generic classes. Parameters are used inside definitions, while arguments are supplied outside them; the article also discusses Kotlin type inference.

### Source excerpt

If you've ever had trouble remembering the difference between parameters and arguments, today's article is for you! Understanding this distinction can help when we're talking about functions, and it can help even more when we're talking about generics. Parameters and Arguments - the TL;DR It's a parameter when you're inside the definition. It's an argument when you're outside the definition. The easiest way to recall the difference between the two is to associate the word argument with the word outside, by remembering this phrase:

## 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: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [class](<https://devfeed.tech/tags/class.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>), [guide](<https://devfeed.tech/tags/guide.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>), [star-projection](<https://devfeed.tech/tags/star-projection.md>), [type-projection](<https://devfeed.tech/tags/type-projection.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 tutorial explains how Kotlin star-projections work when a function must accept any kind of a generic. It applies subtyping rules for accepted and returned types to compare star-projections with other type-safe solutions.

### 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: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [generics](<https://devfeed.tech/topics/generics.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [function](<https://devfeed.tech/tags/function.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [generics](<https://devfeed.tech/tags/generics.md>), [guide](<https://devfeed.tech/tags/guide.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [interface](<https://devfeed.tech/tags/interface.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

A tutorial explaining generic variance and type projections in Kotlin. It applies two subtype rules to show why covariance and contravariance work and uses a generic animal collection as an example.

### 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.

## An Illustrated Guide to Covariance and Contravariance in Kotlin

DevFeed: [An Illustrated Guide to Covariance and Contravariance in Kotlin](<https://devfeed.tech/articles/an-illustrated-guide-to-covariance-and-contravariance-in-kotlin-25035.md>)

Original publisher: [Read original article](<https://typealias.com/guides/illustrated-guide-covariance-contravariance/>)

Author: author@typealias.com (Dave Leeds)

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

Content type: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [generics](<https://devfeed.tech/topics/generics.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>)

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

### AI overview

This illustrated Kotlin tutorial explains the foundational concepts behind generic variance. It focuses on subtyping, function arguments and results, and how covariance and contravariance appear in class and interface inheritance.

### Source excerpt

Generics can often seem confusing. How often have you started to solve a problem with generics, only to realize that they don't quite work like you thought they did? The good news is that there are some simple, foundational concepts that underpin generic variance. And once you understand those concepts, you won't have to memorize acronyms or resort to trial-and-error - you'll simply understand how and why they work! In this article, I'm going to cover these foundational concepts, and then demonstrate how they play out in Kotlin class and interface inheritance.

## 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: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Code](<https://devfeed.tech/topics/code.md>), [context](<https://devfeed.tech/topics/context.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [compiler](<https://devfeed.tech/tags/compiler.md>), [context](<https://devfeed.tech/tags/context.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generics](<https://devfeed.tech/tags/generics.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [parameter](<https://devfeed.tech/tags/parameter.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-parameters](<https://devfeed.tech/tags/type-parameters.md>), [type-projection](<https://devfeed.tech/tags/type-projection.md>), [types](<https://devfeed.tech/tags/types.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

This article explains type arguments in generics, including how they are specified in type declarations and function calls, inferred by the compiler, and used with variance annotations for type projection. It also distinguishes type arguments from type parameters.

### 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: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Code](<https://devfeed.tech/topics/code.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [function](<https://devfeed.tech/tags/function.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generics](<https://devfeed.tech/tags/generics.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [reification](<https://devfeed.tech/tags/reification.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

This tutorial explains type parameters in generics: how they are declared and used, naming conventions, constraints that limit allowable types, variance in generic subtyping, and reified type parameters.

### 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.

## Friday Q&A 2017-12-08: Type Erasure in Swift

DevFeed: [Friday Q&A 2017-12-08: Type Erasure in Swift](<https://devfeed.tech/articles/friday-q-a-2017-12-08-type-erasure-in-swift-30626.md>)

Original publisher: [Read original article](<http://www.mikeash.com/pyblog/friday-qa-2017-12-08-type-erasure-in-swift.html>)

Author: Mike Ash

Published: 2017-12-15T14:09:00Z

Content type: tutorial

Language: en

Sources: [Mike Ash](<https://devfeed.tech/sources/mike-ash.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [generics](<https://devfeed.tech/topics/generics.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [generics](<https://devfeed.tech/tags/generics.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [swift](<https://devfeed.tech/tags/swift.md>), [types](<https://devfeed.tech/tags/types.md>)

### AI overview

This tutorial explains type erasure in Swift, including why it is useful for hiding implementation details, preventing concrete types from spreading through a codebase, and allowing distinct types to interoperate. It discusses limitations involving generics and protocols with associated types, and describes using Any to erase an arbitrary type with a small complexity and runtime cost.

### Source excerpt

You might have heard the term type erasure. You might have even used type-erased types in the standard library, such as AnySequence. But what exactly is type erasure and how do you do it yourself? In this article, I'll explore type erasure, why you'd want it, and how to make it happen, a topic suggested by Lorenzo Boaro. (Read More)

## 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: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Java](<https://devfeed.tech/topics/java.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>)

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [function](<https://devfeed.tech/tags/function.md>), [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>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [properties](<https://devfeed.tech/tags/properties.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

This tutorial explains invariance in generic subtyping. It shows that generic types can remain unrelated even when their component types have a subtype relationship, and discusses default invariance in Kotlin and Java, multiple type parameters, and variance in inherited properties and function types.

### 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: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>), [Code](<https://devfeed.tech/topics/code.md>), [Java](<https://devfeed.tech/topics/java.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [contravariance](<https://devfeed.tech/tags/contravariance.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generics](<https://devfeed.tech/tags/generics.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.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

This tutorial explains contravariance as a type relationship in which subtyping proceeds in opposite directions. It uses inheritance and generic classes to show how contravariant type parameters affect subtype relationships, usage, and the ability to return values of the parameter type.

### 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.

## Covariance

DevFeed: [Covariance](<https://devfeed.tech/articles/covariance-25011.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2017-11-14T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>)

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

### AI overview

This tutorial explains covariance in type systems, focusing on how subtype relationships behave with generic types. It uses Kotlin examples to distinguish covariant read-only types from invariant mutable types, shows how to declare covariance with the out annotation, and discusses related constraints involving function arguments, properties, and inheritance.

### Source excerpt

On the surface, subtypes seem straightforward. Most programmers who write object-oriented code are familiar with the concept of inheritance, and how you can pass off a subclass as if it were its superclass. But subtyping rules aren't always as intuitive when you start working with generics. What is Covariance? Covariance describes a relationship between two sets of types where they both subtype in the same direction. For example, for our first set of types, here are two classes, A and B, where B is a subtype of A:

[Next page](<https://devfeed.tech/topics/generics.md?cursor=WyIyMDE3LTExLTE0VDAwOjAwOjAwKzAwOjAwIiwgIjJkY2NmYmJhLTk5NDAtNGY4Zi1iMzdjLWQxNTcwYjkwMWZmNCJd>)