---
title: "Discussion on \"How to return 2+ values with 0 allocation in Kotlin\" | Hashnode"
description: "Discussion on \"How to return 2+ values with 0 allocation in Kotlin\". Since Kotlin 1.3, with contracts and inline functions, it's possible to return more than one value, without allocation any extra class. See how."
url: "https://hashnode.com/posts/how-to-return-2-values-with-0-allocation-in-kotlin/61487096699fe76cd34845e5"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to return 2+ values with 0 allocation in Kotlin](https://blog.louiscad.com/how-to-return-2-values-with-0-allocation-in-kotlin?utm_source=hashnode&utm_medium=feed)

Since Kotlin 1.3, with contracts and inline functions, it's possible to return more than one value, without allocation any extra class. See how.

Sep 20, 2021 · 5 min read · blog.louiscad.com  
Updated Nov 14, 2021  
Read the article

-   [#kotlin](https://hashnode.com/tag/kotlin)

## Written by

[Louis CAD](https://hashnode.com/@LouisCAD)

@LouisCAD · Tours, France

  
[View profile](https://hashnode.com/@LouisCAD)

Kotlin GDE

I contribute to the Kotlin ecosystem through open source projects, issue reporting, talks at conferences, and more. I've been developing for Android since 2014, using Kotlin since 2016, with coroutines since 2017, and in 2018, I started doing multiplatform development in libraries, then in production apps.

## Responses 2

Markdown supported · ⌘↵ to post

[Roman Dawydkin](https://hashnode.com/@Beholder)

[Dec 9, 2021](https://hashnode.com/posts/how-to-return-2-values-with-0-allocation-in-kotlin/61487096699fe76cd34845e5/comment/61b281036a81cf6b31dfd1c0)

You are "saving" allocations, but bloating bytecode with inline functions. Is it worth it? And if you remove the inline modifier, there will be allocations for lambdas. Just let the GC do the work.

[Louis CAD](https://hashnode.com/@LouisCAD)

[Dec 10, 2021](https://hashnode.com/posts/how-to-return-2-values-with-0-allocation-in-kotlin/61487096699fe76cd34845e5/comment/61b281036a81cf6b31dfd1c0#reply-61b33213fccdb516104ba07e)

Inline functions don't all bloat the bytecode. In the example, there's 3 function calls, 3 if/else, and a few local variables introduced.

Using a class would actually lead to more bytecode bloat, I'll let you check that.

Note that I never said to never use a class to return multiple values, I just showed another way, which makes sense in **some** cases like the one I showed.

[Mausam Singh](https://hashnode.com/@mausamsingh470)

[Sep 26, 2021](https://hashnode.com/posts/how-to-return-2-values-with-0-allocation-in-kotlin/61487096699fe76cd34845e5/comment/61508dae94bb297e1aad85ec)

That's amazing and well written blog, I am glad you have started to doing blog #Android 😃 😃
