# constructor

Published articles for constructor.

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

## Metro DI for Ktor Backend: From a God Object through manual DI to Constructor Injection

DevFeed: [Metro DI for Ktor Backend: From a God Object through manual DI to Constructor Injection](<https://devfeed.tech/articles/metro-di-for-ktor-backend-from-a-god-object-through-manual-di-to-constructor-injection-22966.md>)

Original publisher: [Read original article](<https://funkymuse.github.io/posts/metro-di-ktor-server/>)

Author: FunkyMuse

Published: 2026-05-15T15:35:00Z

Content type: tutorial

Language: en

Sources: [FunkyMuse](<https://devfeed.tech/sources/funkymuse.md>)

Topics: [Ktor](<https://devfeed.tech/topics/ktor.md>), [Back end](<https://devfeed.tech/topics/backend.md>), [modules](<https://devfeed.tech/topics/modules.md>)

Tags: [backend](<https://devfeed.tech/tags/backend.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [di](<https://devfeed.tech/tags/di.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [ktor](<https://devfeed.tech/tags/ktor.md>), [redis](<https://devfeed.tech/tags/redis.md>), [server](<https://devfeed.tech/tags/server.md>), [unit-test](<https://devfeed.tech/tags/unit-test.md>)

### AI overview

This article describes replacing manual dependency injection in a Ktor backend with Metro. It explains how default constructor parameters and a central BackendComponent can accidentally couple tests to real dependencies such as Redis, while Metro wires constructor parameters at compile time and removes those defaults.

### Source excerpt

The Starting Point: a God Object When Rudio was a created a few months ago it used the simplest possible DI: one big object BackendComponent with everything wired manually via by lazy and lateinit var. No framework, no annotations, no ceremony, then i started adding things and manual DI became a tedious and tiring task because everywhere i used default parameters to achieve default constructor...

## Unexpected inconsistency in records

DevFeed: [Unexpected inconsistency in records](<https://devfeed.tech/articles/unexpected-inconsistency-in-records-30702.md>)

Original publisher: [Read original article](<https://codeblog.jonskeet.uk/2025/07/19/unexpected-inconsistency-in-records/>)

Author: jonskeet

Published: 2025-07-19T13:04:48Z

Content type: tutorial

Language: en

Sources: [Jon Skeet](<https://devfeed.tech/sources/jon-skeet.md>)

Topics: [C#](<https://devfeed.tech/topics/csharp.md>), [Code](<https://devfeed.tech/topics/code.md>), [bug](<https://devfeed.tech/topics/bug.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [code](<https://devfeed.tech/tags/code.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [mutation](<https://devfeed.tech/tags/mutation.md>), [properties](<https://devfeed.tech/tags/properties.md>)

### AI overview

The article explains an inconsistency in C# records when nondestructive mutation is combined with derived data initialized from constructor parameters. The with-style operation uses a generated copy constructor, copying existing fields rather than recalculating derived values, which can leave the copied record internally inconsistent.

### Source excerpt

Unexpected inconsistency in records The other day, I was trying to figure out a bug in my code, and it turned out to be a misunderstanding on my part as to how C# records work. It's entirely possible that I'm the only one who expected them to work in the way that I did, but ... Continue reading Unexpected inconsistency in records ->

## Objects in Kotlin

DevFeed: [Objects in Kotlin](<https://devfeed.tech/articles/objects-in-kotlin-39337.md>)

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

Published: 2023-07-17T00:01:00Z

Content type: tutorial

Language: en

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

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

Tags: [class](<https://devfeed.tech/tags/class.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [object](<https://devfeed.tech/tags/object.md>), [synchronization](<https://devfeed.tech/tags/synchronization.md>), [syntax](<https://devfeed.tech/tags/syntax.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This Kotlin tutorial explains how to create objects with object expressions and object declarations. It covers anonymous objects, inheritance and interface implementation, object scope, singleton behavior, and practical uses such as listeners and synchronization locks.

### Source excerpt

What is object expression, object declaration and companion objects, and how we use them.

## Avoid Java double brace initialization

DevFeed: [Avoid Java double brace initialization](<https://devfeed.tech/articles/avoid-java-double-brace-initialization-25619.md>)

Original publisher: [Read original article](<https://blog.p-y.wtf/avoid-java-double-brace-initialization>)

Author: Pierre-Yves Ricau

Published: 2023-06-27T20:58:00Z

Content type: tutorial

Language: en

Sources: [Py's blog](<https://devfeed.tech/sources/py-s-blog.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Code](<https://devfeed.tech/topics/code.md>), [Android](<https://devfeed.tech/topics/android.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [crash-reporting](<https://devfeed.tech/tags/crash-reporting.md>), [gc](<https://devfeed.tech/tags/gc.md>), [global](<https://devfeed.tech/tags/global.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [java](<https://devfeed.tech/tags/java.md>), [leak](<https://devfeed.tech/tags/leak.md>), [leakcanary](<https://devfeed.tech/tags/leakcanary.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-leak](<https://devfeed.tech/tags/memory-leak.md>), [object](<https://devfeed.tech/tags/object.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [subclass](<https://devfeed.tech/tags/subclass.md>)

### AI overview

This tutorial explains how Java double brace initialization can cause memory leaks. An anonymous HashMap subclass implicitly retains its outer Activity, so a breadcrumb stored by a singleton BugSnag client can keep a destroyed Android Activity in memory. The article recommends avoiding the pattern and using explicit initialization or Kotlin.

### Source excerpt

TL;DR Avoid doing this: new HashMap() {{ put("key", value); }}; Leak Trace I was recently looking at the following leak trace from LeakCanary: ┬─── │ GC Root: Global variable in native code │ ├─ com.bugsnag.android.AnrPlugin instan...

## Enum classes in Kotlin

DevFeed: [Enum classes in Kotlin](<https://devfeed.tech/articles/enum-classes-in-kotlin-39330.md>)

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

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

Content type: tutorial

Language: en

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

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

Tags: [abstract-class](<https://devfeed.tech/tags/abstract-class.md>), [class](<https://devfeed.tech/tags/class.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [enum](<https://devfeed.tech/tags/enum.md>), [enum-class](<https://devfeed.tech/tags/enum-class.md>), [enums](<https://devfeed.tech/tags/enums.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [property](<https://devfeed.tech/tags/property.md>), [superclass](<https://devfeed.tech/tags/superclass.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This Kotlin tutorial explains how to define and use enum classes to represent finite sets of values. It covers enum values and their order, companion object utilities, exhaustive when conditions, stored state, and custom methods.

### Source excerpt

What are enum classes in Kotlin and how do we use them.

## How to create a parameterized base test class in Kotlin

DevFeed: [How to create a parameterized base test class in Kotlin](<https://devfeed.tech/articles/how-to-create-a-parameterized-base-test-class-in-kotlin-25575.md>)

Original publisher: [Read original article](<https://www.marcogomiero.com/posts/2023/parameterized-kotlin-base-test/>)

Author: Marco Gomiero

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

Content type: tutorial

Language: en

Sources: [Posts on Marco Gomiero](<https://devfeed.tech/sources/posts-on-marco-gomiero.md>)

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

Tags: [argument](<https://devfeed.tech/tags/argument.md>), [class](<https://devfeed.tech/tags/class.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This tutorial explains how to create a parameterized base test class in Kotlin using JUnit 4's Parameterized test runner. It describes defining test arguments in a companion object, accepting an argument in the base-class constructor, and having test classes reuse the shared setup while running with different arguments.

### Source excerpt

One exciting feature of JUnit 4 (and 5 as well, but this post will be focused on JUnit 4) is the possibility of running the same test with different input arguments. That is made possible by a custom test runner called Parameterized, which will inject the provided arguments in the constructor of the test class. Instead, the different arguments must be defined in the companion object of the test class.

## Haskell 101 Lecture Notes

DevFeed: [Haskell 101 Lecture Notes](<https://devfeed.tech/articles/haskell-101-lecture-notes-27923.md>)

Original publisher: [Read original article](<http://alt-romes.github.io/posts/lectures/2022-05-04-lecture.html>)

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

Content type: tutorial

Language: en

Sources: [Romes' Musings](<https://devfeed.tech/sources/romes-musings.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Programming language](<https://devfeed.tech/topics/programming-language.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [abstraction](<https://devfeed.tech/tags/abstraction.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [function](<https://devfeed.tech/tags/function.md>), [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [pattern-matching](<https://devfeed.tech/tags/pattern-matching.md>), [polymorphism](<https://devfeed.tech/tags/polymorphism.md>)

### AI overview

Haskell 101 lecture notes introducing functions, function abstraction and application, expressions, values, types, algebraic data types, construction and deconstruction, pattern matching, polymorphism, and type constructors.

### Source excerpt

Contents 1 Functions, Computations: Abstraction and application 2 Expressions, Values, Types 3 ADTs, Construction, Deconstruction 4 Polymorphism 5 Non-nullary type constructors, Kinds 1 Functions, Computations: Abstraction and application What is a function? f(x) = 4x + 2? And what's function application? f(x) = 4x + 2 f(5) = ? In mathematics, function application is the act of applying a function to an argument from its domain so as to obtain the corresponding value from its range. In this sense, function application can be thought of as the opposite of function abstraction. In functional programming languages, computations are based on function abstraction and application. An abstraction, a.k.a a function, is denoted through the lambda notation (\x -> ...). An application, a.k.a function application, is denoted by juxtaposition: an expression followed by another expression represents the application of the first expression to the following one. f = \x -> 4 * x + 2 -- `f` is an abstraction f 5 -- application of `f` to `5` 2 Expressions, Values, Types Haskell is a purely functional programming language. As such, all computations are done via the evaluation of expressions (syntactic terms) to yield values (abstract entities that we regard as answers). Every value has an associated type (intuitively, we can think of types as sets of values). 5 :: Integer 'a' :: Char inc :: Integer -> Integer [1,2,3] :: [Integer] ('b', 4) :: (Char, Int) sum [1,2,3] :: Integer inc 5 :: Integer sum :: [Integer] -> Integer The :: can be read "has type". All expression evaluate to a value, and all values have types, which means all expressions have types too. Above are some of the common types. Which of the following are expressions, and which are values? What are the types of the expressions? product [1,2,3] product [1,2,3] They are all expressions, and only the first two are values. The first one is a function abstraction, which is a value, the second one is a value constructed with the

## Hands on Jetpack Compose VisualTransformation to create a phone number formatter

DevFeed: [Hands on Jetpack Compose VisualTransformation to create a phone number formatter](<https://devfeed.tech/articles/hands-on-jetpack-compose-visualtransformation-to-create-a-phone-number-formatter-25943.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/hands-on-jetpack-compose-visualtransformation-to-create-a-phone-number-formatter-99b0347fc4f6?source=rss-cbfc736ddcd3------2>)

Author: Julien Salvi

Published: 2021-12-21T15:05:42Z

Content type: tutorial

Language: en

Sources: [Stories by Julien Salvi on Medium](<https://devfeed.tech/sources/stories-by-julien-salvi-on-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Compose](<https://devfeed.tech/topics/compose.md>), [Design system](<https://devfeed.tech/topics/design-system.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Google](<https://devfeed.tech/topics/google.md>)

Tags: [aircall](<https://devfeed.tech/tags/aircall.md>), [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [component](<https://devfeed.tech/tags/component.md>), [compose](<https://devfeed.tech/tags/compose.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [design-system](<https://devfeed.tech/tags/design-system.md>), [filter](<https://devfeed.tech/tags/filter.md>), [function](<https://devfeed.tech/tags/function.md>), [google](<https://devfeed.tech/tags/google.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [mapping](<https://devfeed.tech/tags/mapping.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [transformation](<https://devfeed.tech/tags/transformation.md>), [ui](<https://devfeed.tech/tags/ui.md>)

### AI overview

This tutorial explains how to use Jetpack Compose's VisualTransformation to format phone-number input for international display. It covers the filter() function, TransformedText, and OffsetMapping for mapping positions between original and transformed text.

### Source excerpt

At Aircall, we are currently rewriting our design system with Jetpack Compose, the new UI framework made by Google. One of our UI component is a text input that formats a phone number to its international format according to its origin country. With the View UI toolkit, we can use a PhoneNumberFormattingTextWatcher, which is available since API 1, to format the input text. But no equivalent has been implemented with Jetpack Compose so far. In this article we are going to cover how we managed to create a reliable alternative for Compose with VisualTransformation. VisualTransformation explained First, let's have a look at the VisualTransformation interface to understand how it works under the hood and how you can use it to format the input text of a TextField as you wish. https://medium.com/media/bb42609ef6212c4b0f63f06f83c0534c/href In order to filter the text, you will need to implement the filter() function which takes the original text to transform as a parameter and returns a TransformedText where all the magic happens! If we take a look at the constructor it takes a text (which will be transformed) and an OffsetMapping which provides a bidirectional mapping between the original text and the new one. Which means that we'll need to implement the transformation from and to the original. Let's have a look at the password transformation that the framework provides to see the OffsetMapping in action: https://medium.com/media/5e50cd5af8fd0d3acd9300d03665735b/href Here, the implementation is pretty straightforward as we just need to transform the input text where every character will be replaced by a mask, so the text will have the same length. The transformed text will contain the mapped text and the offsetMapping will handle the transformation. Here, as we don't have any extra character to be displayed in the returned text, the two functions will return the original offset. The two transformations can become a bit more complex if we need to display additional characte

## Effective Kotlin Item 32: Consider factory functions instead of secondary constructors

DevFeed: [Effective Kotlin Item 32: Consider factory functions instead of secondary constructors](<https://devfeed.tech/articles/effective-kotlin-item-32-consider-factory-functions-instead-of-secondary-constructors-39279.md>)

Original publisher: [Read original article](<https://kt.academy/article/ek-factory-functions>)

Published: 2021-07-25T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [functions](<https://devfeed.tech/topics/functions.md>), [constructor](<https://devfeed.tech/topics/constructor.md>), [object](<https://devfeed.tech/topics/object.md>), [interface](<https://devfeed.tech/topics/interface.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>)

Tags: [constructor](<https://devfeed.tech/tags/constructor.md>), [functions](<https://devfeed.tech/tags/functions.md>), [interface](<https://devfeed.tech/tags/interface.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [object](<https://devfeed.tech/tags/object.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This article explains why Kotlin factory functions are often preferable to secondary constructors for complex object creation. It covers clearer naming, avoiding constructor conflicts, returning subtype implementations behind interfaces, and allowing platform-specific or optimized implementations.

### Source excerpt

What factory functions are and why they are so important patterns for object creation.

## Your Compiler is already part of your Security Team

DevFeed: [Your Compiler is already part of your Security Team](<https://devfeed.tech/articles/your-compiler-is-already-part-of-your-security-team-41535.md>)

Original publisher: [Read original article](<https://dfa1.github.io/articles/your-compiler-is-already-part-of-your-security-team.html>)

Author: Davide Angelocola

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

Content type: article

Language: en

Sources: [Davide Angelocola](<https://devfeed.tech/sources/davide-angelocola.md>)

Topics: [Security](<https://devfeed.tech/topics/security.md>), [Java](<https://devfeed.tech/topics/java.md>), [vulnerability](<https://devfeed.tech/topics/vulnerability.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [code](<https://devfeed.tech/tags/code.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [java](<https://devfeed.tech/tags/java.md>), [security](<https://devfeed.tech/tags/security.md>), [type-system](<https://devfeed.tech/tags/type-system.md>), [validation](<https://devfeed.tech/tags/validation.md>), [vulnerability](<https://devfeed.tech/tags/vulnerability.md>)

### AI overview

This article argues that domain-specific types can make invalid values unrepresentable and shift validation into the compiler and type system. It uses a Java example involving swapped integer arguments and warns that unbounded regular-expression validation can enable ReDoS through a single HTTP request.

### Source excerpt

It's 3am. Your phone is ringing. A few hours earlier you deployed a hotfix -- straightforward change, reviewed in a hurry, went out clean. Now some important data is being published under the wrong market. Instruments from exchange A showing up under exchange B. Clients are seeing it. Someone is already asking if it's a breach. It isn't. It's worse, in a way: the hotfix swapped two arguments. The method took a marketId and an instrumentId, both ints, and the caller got them the wrong way round. The compiler saw two ints, both positive, both in range. Code compiled, tests passed, CI was green.

## Examples of Classes in Kotlin

DevFeed: [Examples of Classes in Kotlin](<https://devfeed.tech/articles/examples-of-classes-in-kotlin-25009.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2020-08-31T00: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>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [concepts](<https://devfeed.tech/tags/concepts.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [examples](<https://devfeed.tech/tags/examples.md>), [function](<https://devfeed.tech/tags/function.md>), [generic](<https://devfeed.tech/tags/generic.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [property](<https://devfeed.tech/tags/property.md>), [reference](<https://devfeed.tech/tags/reference.md>), [visibility-modifier](<https://devfeed.tech/tags/visibility-modifier.md>)

### AI overview

A quick reference to creating classes in Kotlin, including a simple class with no properties or functions. It explains that classes combine variables and functions into a single unit.

### Source excerpt

One core concept in Kotlin is a class, which allows you to combine variables and functions into a single unit. This article is a quick reference that shows how to create classes in Kotlin. There's also a full article called Introduction to Classes and Objects, which is a gentle introduction to these concepts, so if you're new to the language, you might want to start there! A Simple Class For a class that has no properties or functions, you can create a class in Kotlin with very little code:

## Introduction to Classes and Objects

DevFeed: [Introduction to Classes and Objects](<https://devfeed.tech/articles/introduction-to-classes-and-objects-25048.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2020-06-29T00: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>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [function](<https://devfeed.tech/tags/function.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [object](<https://devfeed.tech/tags/object.md>), [programming](<https://devfeed.tech/tags/programming.md>), [property](<https://devfeed.tech/tags/property.md>), [types](<https://devfeed.tech/tags/types.md>), [visibility-modifier](<https://devfeed.tech/tags/visibility-modifier.md>)

### AI overview

A Kotlin tutorial chapter introduces classes as a way to combine related variables and functions into new types. It uses a circle example and begins by defining an empty class before adding members step by step.

### Source excerpt

In Chapter 1, we learned about a variety of types in Kotlin, such as Double, String, and Boolean. Get ready, because in this chapter, we're going to start creating our very own types! We'll put variables and functions together into a class. Let's get started! Putting Variables and Functions Together As you might recall, we started off this book by creating variables to hold things pertaining to a circle, such as its radius and circumference.

## Why Large Dependency-Injection Constructors Signal a Single-Responsibility Problem

DevFeed: [Why Large Dependency-Injection Constructors Signal a Single-Responsibility Problem](<https://devfeed.tech/articles/the-forgotten-art-of-construction-25893.md>)

Original publisher: [Read original article](<https://proandroiddev.com/the-forgotten-art-of-construction-cfedc368e67f?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2020-06-22T17:39:16Z

Content type: opinion

Language: en

Sources: [Stories by Danny Preussler on Medium](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [clean-code](<https://devfeed.tech/topics/clean-code.md>), [Dagger](<https://devfeed.tech/topics/dagger.md>), [koin](<https://devfeed.tech/topics/koin.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [clean-code](<https://devfeed.tech/tags/clean-code.md>), [code](<https://devfeed.tech/tags/code.md>), [code-smells](<https://devfeed.tech/tags/code-smells.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [koin](<https://devfeed.tech/tags/koin.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>)

### AI overview

The article argues that dependency-injection tools can hide overly large constructors. It presents large constructors as a code smell that may indicate a violation of the Single Responsibility Principle, and notes that they make classes harder to test.

### Source excerpt

How tools made us forget how to write sane constructors https://unsplash.com/photos/qvBYnMuNJ9A In an ideal world, developers get smarter every day. The code we write this year should be better than the code we wrote 10 years ago, which in turn should be better than the code 20 years ago. Today we have better tools, more modern languages, and better practices. But as often in life, we realize we are not living in that ideal world. In nearly every codebase I see today, there are things that would shock a developer two decades ago. I am speaking of what Mark Seemann called "Constructor Over Injection". We've all learned to inject our dependencies into constructors. And ideally use a tool for that like Spring or Dagger. If you look at some random classes from your codebase, how many fields are you injecting? Three? Five? More? I'm pretty sure you easily can find classes with even more, like this one: class ProfilePresenter @Inject constructor( @MainThreadScheduler private val mainScheduler: Scheduler, @IOScheduler private val ioScheduler: Scheduler, private val profileApi: ProfileApi, private val userRepository: UserRepository, private val analytics: Analytics, private val errorReporter: ErrorReporter private val referrerTracker: ReferrerTracker, private val shareTracker: ShareTracker, private val tracksRepository: TracksRepository, private val playlistRepository: PlaylistRepository ) If you would show this constructor to a developer from 20 years ago they would probably look at you as if you would be crazy. No one would want to call this constructor and provide all these parameters. But these days we don't care. We don't have to. We have a tool that will provide us with all those parameters, right? This does not make it right though! The proof If you would use some manual injection code or a service locator like Koin, you would notice more what's going on because you would need to write code like this: ProfilePresenter(get(), get(), get(), get(), get(), get(), get(),

## Introduction to Dependency Injection with Dagger for Java and Android

DevFeed: [Introduction to Dependency Injection with Dagger for Java and Android](<https://devfeed.tech/articles/introduction-to-dagger-di-by-a-life-way-25731.md>)

Original publisher: [Read original article](<https://blog.shreyaspatil.dev/introduction-to-dagger-di-by-a-life-way-d34f62540329/>)

Author: Shreyas Patil

Published: 2020-03-15T07:54:11Z

Content type: tutorial

Language: en

Sources: [Shreyas Patil's Blog](<https://devfeed.tech/sources/shreyas-patil-s-blog.md>)

Topics: [Dagger](<https://devfeed.tech/topics/dagger.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [Android](<https://devfeed.tech/topics/android.md>), [Code](<https://devfeed.tech/topics/code.md>), [Java](<https://devfeed.tech/topics/java.md>), [Framework](<https://devfeed.tech/topics/framework.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [app-architecture](<https://devfeed.tech/tags/app-architecture.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [component](<https://devfeed.tech/tags/component.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [di](<https://devfeed.tech/tags/di.md>), [getting-started](<https://devfeed.tech/tags/getting-started.md>), [java](<https://devfeed.tech/tags/java.md>), [learn](<https://devfeed.tech/tags/learn.md>), [object](<https://devfeed.tech/tags/object.md>), [others](<https://devfeed.tech/tags/others.md>), [parameter](<https://devfeed.tech/tags/parameter.md>)

### AI overview

This tutorial introduces Dependency Injection and Dagger, explaining how Dagger is a static, compile-time framework for Java and Android. It uses a life-needs analogy and a sequence of dependent classes to demonstrate constructor injection and dependency creation.

### Source excerpt

Demystifying Dependency Injection with Dagger. Learn DI concepts through real-life analogies and simplify your Android app architecture.

## Time Travel with JVM

DevFeed: [Time Travel with JVM](<https://devfeed.tech/articles/time-travel-with-jvm-24838.md>)

Original publisher: [Read original article](<https://alidg.me/blog/2020/2/23/time-travel-jvm>)

Author: Alimate

Published: 2020-02-23T00:00:00Z

Content type: tutorial

Language: en

Sources: [Ali Dehghan - Kemikit](<https://devfeed.tech/sources/ali-dehghan-kemikit.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Finagle](<https://devfeed.tech/topics/finagle.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [bytecode](<https://devfeed.tech/tags/bytecode.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [java](<https://devfeed.tech/tags/java.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [object](<https://devfeed.tech/tags/object.md>), [process](<https://devfeed.tech/tags/process.md>)

### AI overview

This article demonstrates how a Java object can be allocated without calling its constructor. It explains that the object receives default field values during JVM initialization, while constructor-based initialization is skipped, and cautions against using the demonstrated approach.

### Source excerpt

Let's allocate a Java object without calling its constructor!

## Let's Build A Simple Interpreter. Part 18: Executing Procedure Calls

DevFeed: [Let's Build A Simple Interpreter. Part 18: Executing Procedure Calls](<https://devfeed.tech/articles/let-s-build-a-simple-interpreter-part-18-executing-procedure-calls-33321.md>)

Original publisher: [Read original article](<https://ruslanspivak.com/lsbasi-part18/>)

Author: Ruslan Spivak

Published: 2020-02-20T13:00:00Z

Content type: tutorial

Language: en

Sources: [Ruslan Spivak](<https://devfeed.tech/sources/ruslan-spivak.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [function](<https://devfeed.tech/topics/function.md>), [Algorithm](<https://devfeed.tech/topics/algorithm.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [blog](<https://devfeed.tech/tags/blog.md>), [code](<https://devfeed.tech/tags/code.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [create](<https://devfeed.tech/tags/create.md>), [function](<https://devfeed.tech/tags/function.md>), [local-variables](<https://devfeed.tech/tags/local-variables.md>), [object](<https://devfeed.tech/tags/object.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [program](<https://devfeed.tech/tags/program.md>), [variables](<https://devfeed.tech/tags/variables.md>)

### AI overview

This tutorial extends an interpreter to execute procedure calls. It focuses on procedures that access parameters and local variables, explaining activation records, call-stack handling, procedure execution, and the implementation of the visit_ProcedureCall method.

### Source excerpt

Do the best you can until you know better. Then when you know better, do better. ― Maya Angelou

## Solidity 0.6.x features: try/catch statement

DevFeed: [Solidity 0.6.x features: try/catch statement](<https://devfeed.tech/articles/solidity-0-6-x-features-try-catch-statement-16886.md>)

Original publisher: [Read original article](<https://blog.ethereum.org/en/2020/01/29/solidity-0-6-try-catch>)

Author: Elena Gesheva

Published: 2020-01-29T00:00:00Z

Content type: tutorial

Language: en

Sources: [Ethereum Foundation Blog](<https://devfeed.tech/sources/ethereum-foundation-blog.md>)

Topics: [Solidity](<https://devfeed.tech/topics/solidity.md>)

Tags: [constructor](<https://devfeed.tech/tags/constructor.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [errors](<https://devfeed.tech/tags/errors.md>), [event](<https://devfeed.tech/tags/event.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [external](<https://devfeed.tech/tags/external.md>), [function](<https://devfeed.tech/tags/function.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [property](<https://devfeed.tech/tags/property.md>), [research-development](<https://devfeed.tech/tags/research-development.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

### AI overview

This article explains Solidity 0.6.x try/catch syntax for handling failures in external function calls and contract creation without rolling back state changes made by the calling function. It demonstrates the feature with a factory pattern and explains which errors are and are not caught, including methods for retrieving revert messages.

### Source excerpt

The try/catch syntax introduced in 0.6.0 is arguably the biggest leap in error handling capabilities in Solidity, since reason strings for revert and require were released in v0.4.22. Both try and catch have been reserved keywords since v0.5.9 and now we can use them to handle failures in external function...

## ViewModel. How it works.

DevFeed: [ViewModel. How it works.](<https://devfeed.tech/articles/viewmodel-how-it-works-26015.md>)

Original publisher: [Read original article](<https://unbreakable-titan.medium.com/viewmodel-how-it-works-434282649286?source=rss-e32583ce94d4------2>)

Author: Vladislav Puryev

Published: 2020-01-18T15:40:09Z

Content type: tutorial

Language: en

Sources: [Stories by Vladislav Puryev on Medium](<https://devfeed.tech/sources/stories-by-vladislav-puryev-on-medium.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Code](<https://devfeed.tech/topics/code.md>), [Framework](<https://devfeed.tech/topics/framework.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [Google](<https://devfeed.tech/topics/google.md>), [Java](<https://devfeed.tech/topics/java.md>)

Tags: [abstract-class](<https://devfeed.tech/tags/abstract-class.md>), [android](<https://devfeed.tech/tags/android.md>), [android-framework](<https://devfeed.tech/tags/android-framework.md>), [code](<https://devfeed.tech/tags/code.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [evolution](<https://devfeed.tech/tags/evolution.md>), [java](<https://devfeed.tech/tags/java.md>), [screen](<https://devfeed.tech/tags/screen.md>), [state](<https://devfeed.tech/tags/state.md>), [technical](<https://devfeed.tech/tags/technical.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

This technical tutorial examines how Android ViewModel works internally and how it helps preserve screen state across configuration changes. It explains that ViewModel itself is a simple abstract class and that state retention results from processes within the Android framework, with correct initialization and factories required for dependencies.

### Source excerpt

Android ViewModel. How it works. Hello everybody. This post will be about popular solution from Google for Android developers -- ViewModel (if you are not familiar with it yet -- get started from official documentation). The main goal of article -- show you how viewModel works, how this tool helps us to save state of our screens. First of all it is better to note that viewModel -- is just java code inside Android framework and there is no any magic... almost. This mechanism was improved something about three times from its origin (2017) till the present day. Let's take a look at "Evolution of anatomy". WARNING! This article contains a lot of technical content and internals of Android framework. And please pay attention -- all demonstrated code you can find in your Android Framework using middle-click or ctrl + left-click. There is no any of self-made code -- all is inside Android framework. Attention again -- most of code will be provided in shortened form. Only necessary details. Full versions you can find in Android Framework source codes straight inside your IDE. ViewModel 2017 Honestly, this part (I mean exactly ViewModel's version of 2017) can be unnecessary, because Medium has several articles, that describes viewModel saving state mechanism in first version. I like this one. But I suggest you more code than there. First of all let's take a look at ViewModel class itself. According to official documentation: The ViewModel class allows data to survive configuration changes such as screen rotations. It can lead to research this class. https://medium.com/media/3966f6a014283670bd0d0430100902cd/href It is just simple abstract class. Without any secrets. With one empty method. Can documentation be wrong (or obsolete) so long time? This question is not so obvious. From one side, if you will create your child viewModel and initialize it using constructor, in this case saving states mechanism will not work. But if you are doing everything in the right way (using special initial

## Primaries Matter (a discussion of constructors)

DevFeed: [Primaries Matter (a discussion of constructors)](<https://devfeed.tech/articles/primaries-matter-a-discussion-of-constructors-27078.md>)

Original publisher: [Read original article](<https://zsmb.co/primaries-matter-a-discussion-of-constructors/>)

Author: Márton Braun

Published: 2019-08-12T18:00:00Z

Content type: tutorial

Language: en

Sources: [zsmb.co](<https://devfeed.tech/sources/zsmb-co.md>)

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

Tags: [android](<https://devfeed.tech/tags/android.md>), [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [marton-braun](<https://devfeed.tech/tags/marton-braun.md>), [properties](<https://devfeed.tech/tags/properties.md>), [property](<https://devfeed.tech/tags/property.md>), [scope](<https://devfeed.tech/tags/scope.md>), [zsmb](<https://devfeed.tech/tags/zsmb.md>), [zsmb-co](<https://devfeed.tech/tags/zsmb-co.md>), [zsmb13](<https://devfeed.tech/tags/zsmb13.md>), [zsmbco](<https://devfeed.tech/tags/zsmbco.md>)

### AI overview

A tutorial on Kotlin primary constructors explains their role in class initialization, how constructor properties are initialized in order, and how Kotlin's initialization requirements differ from Java's implicit default values.

### Source excerpt

Primary constructors play a fundamental role in Kotlin classes. Let's take a close look at them, and really understand what exactly is part of a primary constructor, and what makes this constructor so special.

## Unit Testing RxJava Or Coroutine Code With Constructor Injection

DevFeed: [Unit Testing RxJava Or Coroutine Code With Constructor Injection](<https://devfeed.tech/articles/unit-testing-rxjava-or-coroutine-code-with-constructor-injection-22846.md>)

Original publisher: [Read original article](<http://androidessence.com/unit-testing-async-code/>)

Author: Adam McNeilly

Published: 2019-04-30T00:00:00Z

Content type: tutorial

Language: en

Sources: [Android Essence](<https://devfeed.tech/sources/android-essence.md>)

Topics: [Unit testing](<https://devfeed.tech/topics/unit-testing.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [API](<https://devfeed.tech/topics/api.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [apis](<https://devfeed.tech/tags/apis.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [rxjava](<https://devfeed.tech/tags/rxjava.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-testing](<https://devfeed.tech/tags/unit-testing.md>)

### AI overview

This tutorial explains how to unit test asynchronous Android code written with RxJava or Kotlin coroutines. It recommends injecting schedulers or dispatchers through constructors so tests can replace them with immediate, test-friendly implementations and avoid unavailable Android main-thread or looper behavior.

### Source excerpt

Putting aside the long lasting debate right now about whether you should use RxJava or coroutines for your asynchronous code on Android, both camps often hit the same problem. How do I write unit tests for this? Unit testing asynchronous code is tricky, because we may need to know how to properly test callback APIs, or perhaps we just want things to run instantly and not worry about thread changes. We may also be wondering how to handle not having a "main" thread in a junit test, unlike a connected test. This post will be focusing on handling that last one.

## @JvmOverloads for Android Views

DevFeed: [@JvmOverloads for Android Views](<https://devfeed.tech/articles/jvmoverloads-for-android-views-27065.md>)

Original publisher: [Read original article](<https://zsmb.co/jvmoverloads-for-android-views/>)

Author: Márton Braun

Published: 2019-02-22T11:00:00Z

Content type: tutorial

Language: en

Sources: [zsmb.co](<https://devfeed.tech/sources/zsmb-co.md>)

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

Tags: [android](<https://devfeed.tech/tags/android.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [code](<https://devfeed.tech/tags/code.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [convenience](<https://devfeed.tech/tags/convenience.md>), [feature](<https://devfeed.tech/tags/feature.md>), [framework](<https://devfeed.tech/tags/framework.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [marton-braun](<https://devfeed.tech/tags/marton-braun.md>), [zsmb](<https://devfeed.tech/tags/zsmb.md>), [zsmb-co](<https://devfeed.tech/tags/zsmb-co.md>), [zsmb13](<https://devfeed.tech/tags/zsmb13.md>), [zsmbco](<https://devfeed.tech/tags/zsmbco.md>)

### AI overview

This tutorial explains how Kotlin's @JvmOverloads annotation generates Java-compatible overloads and examines why using it for Android custom View constructors can produce behavior different from explicitly defining the constructors.

### Source excerpt

The @JvmOverloads annotation is a convenience feature in Kotlin for interoperating with Java code, but there is one specific use case on Android where it shouldn't be used carelessly.

## Data classes aren't (that) magical

DevFeed: [Data classes aren't (that) magical](<https://devfeed.tech/articles/data-classes-aren-t-that-magical-27059.md>)

Original publisher: [Read original article](<https://zsmb.co/data-classes-arent-that-magical/>)

Author: Márton Braun

Published: 2019-01-16T16:00:00Z

Content type: tutorial

Language: en

Sources: [zsmb.co](<https://devfeed.tech/sources/zsmb-co.md>)

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

Tags: [android](<https://devfeed.tech/tags/android.md>), [classes](<https://devfeed.tech/tags/classes.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [create](<https://devfeed.tech/tags/create.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [destructuring](<https://devfeed.tech/tags/destructuring.md>), [generate](<https://devfeed.tech/tags/generate.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [marton-braun](<https://devfeed.tech/tags/marton-braun.md>), [optional](<https://devfeed.tech/tags/optional.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [properties](<https://devfeed.tech/tags/properties.md>), [zsmb](<https://devfeed.tech/tags/zsmb.md>), [zsmb-co](<https://devfeed.tech/tags/zsmb-co.md>), [zsmb13](<https://devfeed.tech/tags/zsmb13.md>), [zsmbco](<https://devfeed.tech/tags/zsmbco.md>)

### AI overview

This tutorial explains what Kotlin data classes add to regular classes. It covers generated methods, how primary-constructor properties affect those methods, destructuring support, and the copy method with optional named parameters.

### Source excerpt

Data classes are great, but don't underestimate what a regular Kotlin class can do on its own.

## How Does React Tell a Class from a Function?

DevFeed: [How Does React Tell a Class from a Function?](<https://devfeed.tech/articles/how-does-react-tell-a-class-from-a-function-36169.md>)

Original publisher: [Read original article](<https://overreacted.io/how-does-react-tell-a-class-from-a-function/>)

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

Content type: tutorial

Language: en

Sources: [Dan Abramov](<https://devfeed.tech/sources/dan-abramov.md>)

Topics: [React](<https://devfeed.tech/topics/react.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [function](<https://devfeed.tech/tags/function.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [react](<https://devfeed.tech/tags/react.md>)

### AI overview

This article explains how React distinguishes function components from class components and why it must handle them differently. It uses JavaScript concepts including new, instanceof, prototype chains, and this to describe the underlying behavior.

### Source excerpt

We talk about classes, new, instanceof, prototype chains, and API design.

## C++ Quiz #1

DevFeed: [C++ Quiz #1](<https://devfeed.tech/articles/c-quiz-1-30808.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/cpp-quiz-1/>)

Published: 2017-11-30T23:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Parser](<https://devfeed.tech/topics/parser.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code](<https://devfeed.tech/tags/code.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [parsing](<https://devfeed.tech/tags/parsing.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

This C++ tutorial examines how ambiguous parsing affects constructor expressions, temporary objects, and variable shadowing. It explains why similar-looking lines produce different constructor calls and notes a related mutex-locking hazard and an upcoming Clang warning.

### Source excerpt

What is the output of this small snippet that is based on real C++ code? #include <iostream> struct Foo { Foo() { std::cout << "standard" << std::endl; } Foo(const Foo&) { std::cout << "copy" << std::endl; } Foo(int) { std::cout << "int" << std::endl; } Foo(int, int) { std::cout << "int, int" << std::endl; } Foo(const Foo&, int) { std::cout << "Foo, int" << std::endl; } Foo(int, const Foo&) { std::cout << "int, Foo" << std::endl; } }; void f(Foo) {} struct Bar { int m_i; int m_j; Bar() { f(Foo(m_i, m_j)); f(Foo(m_i)); Foo(m_i, m_j); Foo(m_i); Foo(m_i, m_j); } }; int main() { Bar(); } The code compiles without warnings with clang++ 5.0.0 as well as g++ 7.2.0 using -Wall -Wextra. Solution The preliminaries are simple: We have a struct Foo with a few different constructors, each of which prints a text that represents its parameter types. We have a struct Bar with two members, m_i and m_j. The main function calls the standard constructor of Bar. The constructor of Bar is where the magic happens, so let's go through it line by line: f(Foo(m_i, m_j)) creates a temporary Foo object by calling the Foo constructor with m_i and m_j as parameters, so int, int is printed. The resulting Foo object is then passed to the function f. f(Foo(m_i)) works analogously, it calls the Foo constructor with m_i as parameter, so int is printed. The resulting Foo object is then passed to the function f. Foo(m_i, m_j) works the same as the first line, except it doesn't pass the resulting temporary Foo object to a function, so it is destroyed again immediately, int, int is printed again. So far so good, but now look closely. Foo(m_i) surprisingly behaves entirely differently from all the previous lines. It does not call the Foo constructor with m_i as the parameter. Instead it creates a Foo object of the name m_i, just like Foo m_i would. So standard is printed. Now the last line looks just like the third line, but it still does something different. Why? Because the name m_i is no longer referri

[Next page](<https://devfeed.tech/tags/constructor.md?cursor=WyIyMDE3LTExLTMwVDIzOjAwOjAwKzAwOjAwIiwgIjFhZGMxNmQwLTJlNjMtNDcwOS05MTU2LWY4NWY2YTk5ZjE0NCJd>)