# Type Argument

A type argument is a type supplied to a generic function, either explicitly or through compiler inference.

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

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

## How C++ Resolves a Function Call

DevFeed: [How C++ Resolves a Function Call](<https://devfeed.tech/articles/how-c-resolves-a-function-call-21020.md>)

Original publisher: [Read original article](<https://preshing.com/20210315/how-cpp-resolves-a-function-call>)

Author: Jeff Preshing

Published: 2021-03-15T12:10:00Z

Content type: article

Language: en

Sources: [Jeff Preshing](<https://devfeed.tech/sources/jeff-preshing.md>)

Topics: [Tutorial](<https://devfeed.tech/topics/tutorial.md>), [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [Type Argument](<https://devfeed.tech/topics/type-argument.md>), [Jule](<https://devfeed.tech/topics/jule.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [built-in](<https://devfeed.tech/tags/built-in.md>), [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [call](<https://devfeed.tech/tags/call.md>), [career](<https://devfeed.tech/tags/career.md>), [compile](<https://devfeed.tech/tags/compile.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [features](<https://devfeed.tech/tags/features.md>), [function](<https://devfeed.tech/tags/function.md>), [functions](<https://devfeed.tech/tags/functions.md>), [namespaces](<https://devfeed.tech/tags/namespaces.md>), [operator](<https://devfeed.tech/tags/operator.md>), [operators](<https://devfeed.tech/tags/operators.md>), [runtime](<https://devfeed.tech/tags/runtime.md>), [sort](<https://devfeed.tech/tags/sort.md>), [string](<https://devfeed.tech/tags/string.md>), [strings](<https://devfeed.tech/tags/strings.md>), [template](<https://devfeed.tech/tags/template.md>), [templates](<https://devfeed.tech/tags/templates.md>)

### AI overview

C++ resolves function calls at compile time through a sequence of steps: name lookup gathers candidates, including functions found through argument-dependent lookup for unqualified calls; template argument deduction and substitution turn viable templates into functions or remove them when deduction or substitution fails (SFINAE); and overload resolution filters by argument compatibility and constraints before selecting the best viable function. The example shows a namespace function and a function template with identical parameter types; the non-template wins the tie. Better argument conversions take precedence over template status, and a more specialized template can win when earlier rules do not decide the call. If no unambiguous best candidate exists, compilation fails. The article presents a high-level explanation and notes that detailed rules for lookup, conversions, deduction, and specialization are omitted.

### Source excerpt

C is a simple language. You're only allowed to have one function with each name. C++, on the other hand, gives you much more flexibility: You can have multiple functions with the same name (overloading). You can overload built-in operators like + and ==. You can write function templates. Namespaces help you avoid naming conflicts. I like these C++ features. With these features, you can make str1 + str2 return the concatenation of two strings. You can have a pair of 2D points, and another pair of 3D points, and overload dot(a, b) to work with either type. You can have a bunch of array-like classes and write a single sort function template that works with all of them. But when you take advantage of these features, it's easy to push things too far. At some point, the compiler might unexpectedly reject your code with errors like: error C2666: 'String::operator ==': 2 overloads have similar conversions note: could be 'bool String::operator ==(const String &) const' note: or 'built-in C++ operator==(const char *, const char *)' note: while trying to match the argument list '(const String, const char *)' Like many C++ programmers, I've struggled with such errors throughout my career. Each time it happened, I would usually scratch my head, search online for a better understanding, then change the code until it compiled. But more recently, while developing a new runtime library for Plywood, I was thwarted by such errors over and over again. It became clear that despite all my previous experience with C++, something was missing from my understanding and I didn't know what it was. Fortunately, it's now 2021 and information about C++ is more comprehensive than ever. Thanks especially to cppreference.com, I now know what was missing from my understanding: a clear picture of the hidden algorithm that runs for every function call at compile time. This is how the compiler, given a function call expression, figures out exactly which function to call: may performargument-dependentloo

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

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