# val

Published articles for val.

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

## Performance in Jetpack Compose

DevFeed: [Performance in Jetpack Compose](<https://devfeed.tech/articles/performance-in-jetpack-compose-25901.md>)

Original publisher: [Read original article](<https://skyyo.medium.com/performance-in-jetpack-compose-9a85ce02f8f9?source=rss-56174fa84bcc------2>)

Author: Denys Rudenko

Published: 2022-10-03T16:41:03Z

Content type: tutorial

Language: en

Sources: [Stories by Denis Rudenko on Medium](<https://devfeed.tech/sources/stories-by-denis-rudenko-on-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [article](<https://devfeed.tech/tags/article.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compose](<https://devfeed.tech/tags/compose.md>), [false-positive](<https://devfeed.tech/tags/false-positive.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [modifiers](<https://devfeed.tech/tags/modifiers.md>), [performance](<https://devfeed.tech/tags/performance.md>), [recomposition](<https://devfeed.tech/tags/recomposition.md>), [scopes](<https://devfeed.tech/tags/scopes.md>), [skip](<https://devfeed.tech/tags/skip.md>), [ui](<https://devfeed.tech/tags/ui.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>), [variables](<https://devfeed.tech/tags/variables.md>)

### AI overview

A practical guide to improving Jetpack Compose performance through stable parameters, skippable composables, optimized recompositions, remembered lambdas, and compiler and layout-inspector metrics.

### Source excerpt

Article tells about my research on how to write efficient Compose code. It consists of 6 sections and a TL;DR/Summary in the end. We will cover: Optimising recompositions When should you use @Immutable and @Stable annotations; Unstable classes, variables, lambdas; Non-restartable & skippable composables; Lambda modifiers; Passing lambdas providing required fields instead of fields in composables; Inlined composables; When you should use remember { }. We'll be using Compose Compiler Metrics and layout inspector tools to know: - If a class is stable or not; - If the composable function is skippable/restartable; - Amount of skipped recompositions. 1. Unstable objects on UI layer. To understand why we should care about stability, let us peek into a very important metric called skippability. It allows compose runtime to skip recomposition of a composable when all the parameters it uses are considered stable. What is considered stable by the compiler? - All primitive value types: Boolean, Int, Long, Float, Char, etc. - Strings - Lambdas (not always, we will get to it later) We want composable functions to use stable params to become skippable. 1) Don't use var when seeking stability. Fields declared as var are considered unstable: https://medium.com/media/724da23ba38eaa9d3312318e7e8038b9/hrefhttps://medium.com/media/f8dd8a39bce60e48b5ff8bdd4a02b9ef/href UserDetails composable will be recomposed even if the user never gets modified. Using val instead of var in User class will fix this issue. 2) Not all lambdas are considered stable. Let's look at the following examples: https://medium.com/media/fbbff417d165a501b21a3e5d2c6f087f/hrefhttps://medium.com/media/c6aaae01fda67c633edcdf7bb351e620/href Since the lambdas capture outside scopes, they won't be automatically inferred as stable and reused as expected. If the lambda requires access to external variables, the compiler will add those variables as fields, which are passed into the constructor of the lambda. We go a 2 ways of

## How to return 2+ values with 0 allocation in Kotlin

DevFeed: [How to return 2+ values with 0 allocation in Kotlin](<https://devfeed.tech/articles/how-to-return-2-values-with-0-allocation-in-kotlin-26303.md>)

Original publisher: [Read original article](<https://blog.louiscad.com/how-to-return-2-values-with-0-allocation-in-kotlin>)

Author: Louis CAD

Published: 2021-09-20T11:29:26Z

Content type: tutorial

Language: en

Sources: [Louis CAD doing software](<https://devfeed.tech/sources/louis-cad-doing-software.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Refactoring](<https://devfeed.tech/topics/refactoring.md>)

Tags: [compiler](<https://devfeed.tech/tags/compiler.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-languages](<https://devfeed.tech/tags/programming-languages.md>), [refactoring](<https://devfeed.tech/tags/refactoring.md>), [val](<https://devfeed.tech/tags/val.md>)

### AI overview

A Kotlin technique for returning multiple values from a function without extra allocation or a separately named class. The approach combines inline functions or lambdas, read-only properties, and contracts, while noting the potential code-size tradeoff of inlining.

### Source excerpt

The problem Most programming languages, including Kotlin, only allow returning one value, and there's a reason for that: We don't want to depend solely on the order of the parameters, because it can easily break through refactoring, or even before th...

## Random Animating Pie Button

DevFeed: [Random Animating Pie Button](<https://devfeed.tech/articles/random-animating-pie-button-32075.md>)

Original publisher: [Read original article](<https://www.maiatoday.net/p/random-animating-pie-button/>)

Published: 2021-06-16T21:36:11Z

Content type: tutorial

Language: en

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

Topics: [Compose](<https://devfeed.tech/topics/compose.md>), [Canvas](<https://devfeed.tech/topics/canvas.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [animate](<https://devfeed.tech/tags/animate.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [code](<https://devfeed.tech/tags/code.md>), [color](<https://devfeed.tech/tags/color.md>), [component](<https://devfeed.tech/tags/component.md>), [compose](<https://devfeed.tech/tags/compose.md>), [custom](<https://devfeed.tech/tags/custom.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [exploring](<https://devfeed.tech/tags/exploring.md>), [fun](<https://devfeed.tech/tags/fun.md>), [functions](<https://devfeed.tech/tags/functions.md>), [jetpack](<https://devfeed.tech/tags/jetpack.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [random](<https://devfeed.tech/tags/random.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>)

### AI overview

A Jetpack Compose sample demonstrates a custom pie-chart component that draws with Canvas and animates to a random percentage when a button is clicked.

### Source excerpt

I am exploring animations with small sampler functions using Jetpack Compose. This one is a custom component that draws a little pie chart. It will animate a random pie value on the click of the button. data class PieData( val foreground: Color = Color.White, val strokeWidth: Dp = 4.dp, val percentage: Float ) @Composable fun PieStatus( modifier: Modifier = Modifier, pieData: PieData ) { var animationPlayed by remember { mutableStateOf(false) } val currentPercentage = animateFloatAsState( targetValue = if (animationPlayed) pieData.percentage else 0f, animationSpec = tween(1000) ) LaunchedEffect(key1 = true) { animationPlayed = true } Canvas( modifier = modifier ) { val canvasWidth = size.width val canvasHeight = size.height drawCircle( color = pieData.foreground, center = Offset(x = canvasWidth / 2, y = canvasHeight / 2), radius = canvasWidth / 2 - pieData.strokeWidth.toPx(), style = Stroke(width = pieData.strokeWidth.toPx()) ) val arcPadding = pieData.strokeWidth.toPx() * 2 drawArc( color = pieData.foreground, startAngle = -90f, sweepAngle = currentPercentage.value * 360, useCenter = true, topLeft = Offset(arcPadding, arcPadding), size = Size(size.width - (arcPadding * 2f), size.height - (arcPadding * 2f)) ) } } code

## Avoid backing properties for LiveData and StateFlow

DevFeed: [Avoid backing properties for LiveData and StateFlow](<https://devfeed.tech/articles/avoid-backing-properties-for-livedata-and-stateflow-25886.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/avoid-backing-properties-for-livedata-and-stateflow-706006c9867e?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2021-01-12T14:03:52Z

Content type: tutorial

Language: en

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

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

Tags: [abstract-class](<https://devfeed.tech/tags/abstract-class.md>), [android](<https://devfeed.tech/tags/android.md>), [class](<https://devfeed.tech/tags/class.md>), [clean-code](<https://devfeed.tech/tags/clean-code.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [interface](<https://devfeed.tech/tags/interface.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-flow](<https://devfeed.tech/tags/kotlin-flow.md>), [livedata](<https://devfeed.tech/tags/livedata.md>), [stateflow](<https://devfeed.tech/tags/stateflow.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

### AI overview

This Kotlin article argues that developers can avoid duplicated backing properties when exposing LiveData and StateFlow. It proposes separating the public API from the implementation with interfaces or an abstract class, including in ViewModels.

### Source excerpt

https://unsplash.com/photos/OopPIi_A428 If you have ever worked with LiveData you probably have written code similar to this: class MyViewModel: ViewModel() { val loading: LiveData<Boolean> get() = _loading private val _loading = MutableLiveData<Boolean>()} This seems nowadays the typical way developers would expose some immutable LiveData, while being able to have a mutable version inside the implementation we would write data into. Every time I saw, or even had to write, this kind of code something cringed inside me. As I quoted in one of my talks this feeling in our brain is for real: social missteps activate regions in the brain, [..] that have been previously associated with physical pain. As developers, we know something is wrong with this code, right? It also feels like we are writing manual getters and setters here. What's wrong? We could start with the prefix we use for the backing field, although we fought hard for a long time to get rid of prefixes, we accept it here! It is even made it into the official coding conventions. But even if we rename it, it still cringes: class MyViewModel: ViewModel() { val loading: LiveData<Boolean> get() = mutableLoading private val mutableLoading = MutableLiveData<Boolean>()} This duplication feels unneeded! Especially if you write something like a ViewModel that exposed many of these, you get lost in reading the code just by all these duplications. But it's just LiveData? You might think it's just a specialty of LiveData and the future of that construct might be a more limited one. And you would not have this issue with primitives. The language supports this out of the box with a private setter: var secret: String = "Secret" private set But there is a new kid in town: StateFlow needs the same thing! Look at this snippet from the official Jetbrains blog: class DownloadingModel { private val _state = MutableStateFlow<DownloadStatus>(DownloadStatus.NOT_REQUESTED) val state: StateFlow<DownloadStatus> get() = _state This probl

## Kotlin Hyderabad: Introduction to Kotlin

DevFeed: [Kotlin Hyderabad: Introduction to Kotlin](<https://devfeed.tech/articles/kotlin-hyderabad-introduction-to-kotlin-28393.md>)

Original publisher: [Read original article](<https://siddroid.com/post/talk-introduction-to-kotlin-siddhesh-patil-kotlin-hyderabad/>)

Author: Siddhesh Patil

Published: 2020-08-01T10:47:09Z

Content type: article

Language: en

Sources: [Sid Patil - Android Engineer and Kotlin Advocate](<https://devfeed.tech/sources/sid-patil-android-engineer-and-kotlin-advocate.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Android](<https://devfeed.tech/topics/android.md>), [interoperability](<https://devfeed.tech/topics/interoperability.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [arrays](<https://devfeed.tech/tags/arrays.md>), [beginner](<https://devfeed.tech/tags/beginner.md>), [classes](<https://devfeed.tech/tags/classes.md>), [event](<https://devfeed.tech/tags/event.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [interoperability](<https://devfeed.tech/tags/interoperability.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [introduction-to-kotlin](<https://devfeed.tech/tags/introduction-to-kotlin.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-basics](<https://devfeed.tech/tags/kotlin-basics.md>), [kotlin-hyderabad-user-group](<https://devfeed.tech/tags/kotlin-hyderabad-user-group.md>), [kug-hyderabad](<https://devfeed.tech/tags/kug-hyderabad.md>), [language](<https://devfeed.tech/tags/language.md>), [learn](<https://devfeed.tech/tags/learn.md>), [null-safety](<https://devfeed.tech/tags/null-safety.md>), [patil](<https://devfeed.tech/tags/patil.md>), [siddhesh](<https://devfeed.tech/tags/siddhesh.md>), [siddhesh-patil](<https://devfeed.tech/tags/siddhesh-patil.md>), [siddhesh-patil-talks](<https://devfeed.tech/tags/siddhesh-patil-talks.md>), [talk](<https://devfeed.tech/tags/talk.md>), [talks-on-kotlin](<https://devfeed.tech/tags/talks-on-kotlin.md>), [tech-talks-in-hyderabad](<https://devfeed.tech/tags/tech-talks-in-hyderabad.md>), [tools](<https://devfeed.tech/tags/tools.md>), [val](<https://devfeed.tech/tags/val.md>)

### AI overview

A Kotlin User Group Hyderabad event page describing Siddhesh Patil's beginner-level introduction to Kotlin talk. The session covers Kotlin fundamentals, Android development, interoperability, tools, types, null-safety, functions, data classes, collections, control flow, classes, and interfaces.

### Source excerpt

At their monthly event, Siddhesh Patil gives a talk on introduction to Kotlin at Kotlin User Group Hyderabad

## Variables, Expressions, and Types

DevFeed: [Variables, Expressions, and Types](<https://devfeed.tech/articles/variables-expressions-and-types-25065.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2020-03-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: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [developer](<https://devfeed.tech/tags/developer.md>), [expression](<https://devfeed.tech/tags/expression.md>), [fundamentals](<https://devfeed.tech/tags/fundamentals.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [language](<https://devfeed.tech/tags/language.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [programming](<https://devfeed.tech/tags/programming.md>), [statement](<https://devfeed.tech/tags/statement.md>), [types](<https://devfeed.tech/tags/types.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>), [variable](<https://devfeed.tech/tags/variable.md>)

### AI overview

An introductory Kotlin chapter explains variables, expressions, and types. It uses the example of a circle's radius to show how variables represent values and introduces variables as containers for numbers and other data in programming.

### Source excerpt

So you want to be a Kotlin developer? You've come to the right place! This book will take you through the fundamentals of Kotlin, gently introducing you to the most important concepts of the language in order to help you become a proficient Kotlin developer. Even if you're a seasoned professional, it's important to know the fundamentals in order to establish a solid foundation of understanding so that you can be as effective as possible.

## apply() (scope function)

DevFeed: [apply() (scope function)](<https://devfeed.tech/articles/apply-scope-function-25008.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-04T20:06:46Z

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>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>), [Android](<https://devfeed.tech/topics/android.md>)

Tags: [also](<https://devfeed.tech/tags/also.md>), [apply](<https://devfeed.tech/tags/apply.md>), [code](<https://devfeed.tech/tags/code.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [function](<https://devfeed.tech/tags/function.md>), [guide](<https://devfeed.tech/tags/guide.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.md>), [let](<https://devfeed.tech/tags/let.md>), [library](<https://devfeed.tech/tags/library.md>), [object](<https://devfeed.tech/tags/object.md>), [overview](<https://devfeed.tech/tags/overview.md>), [programming](<https://devfeed.tech/tags/programming.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [scope-function](<https://devfeed.tech/tags/scope-function.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [standard](<https://devfeed.tech/tags/standard.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [val](<https://devfeed.tech/tags/val.md>), [variable](<https://devfeed.tech/tags/variable.md>)

### AI overview

An overview of Kotlin's apply() scope function, including its receiver and return value, with examples of using it to initialize objects and configure Android code.

### Source excerpt

Overview The apply() function is a commonly-used scope function defined in the Kotlin standard library. It's frequently used for initializing an object after instantiation. Example val size = "Hello".apply { println(this) }.length In this example, the string "Hello" is printed, and then its length is assigned to the size variable. Characteristics When the apply() extension function executes: the receiver object that .apply() is called upon is available as this the result will be the receiver object Initializing an Object It's common to use apply() to initialize an object after it's been created.

## Higher-Order Function

DevFeed: [Higher-Order Function](<https://devfeed.tech/articles/higher-order-function-25016.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-01T00: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: [argument](<https://devfeed.tech/tags/argument.md>), [class](<https://devfeed.tech/tags/class.md>), [function](<https://devfeed.tech/tags/function.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [product](<https://devfeed.tech/tags/product.md>), [programming](<https://devfeed.tech/tags/programming.md>), [val](<https://devfeed.tech/tags/val.md>), [widget](<https://devfeed.tech/tags/widget.md>)

### AI overview

This article explains that a higher-order function accepts a function as an argument, returns a function as a result, or does both, with Kotlin examples including calculateCost() and getDiscount().

### Source excerpt

A higher-order function is a function does at least one of these: It accepts a function as an argument It returns a function as a result Kotlin supports higher-order functions. In the following example, calculateCost() accepts a function as an argument, and getDiscount() returns a function as a result. Example class Product(val name: String, val price: Double) val shippingCost = 4.0 val taxRate = 0.08 fun main(args: Array<String>) { val product = Product("Widget", 10.

## Kotlin Classes: Syntax, Properties, Constructors, Functions, and Inheritance

DevFeed: [Kotlin Classes: Syntax, Properties, Constructors, Functions, and Inheritance](<https://devfeed.tech/articles/classes-in-kotlin-more-power-with-less-effort-kad-03-27140.md>)

Original publisher: [Read original article](<https://antonioleiva.com/classes-kotlin>)

Published: 2016-12-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

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

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [properties](<https://devfeed.tech/tags/properties.md>), [property](<https://devfeed.tech/tags/property.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>)

### AI overview

A tutorial introducing Kotlin classes and comparing them with Java. It explains class declarations, properties instead of fields, constructors using val or var, functions, and Kotlin's default-closed inheritance behavior with the open modifier.

### Source excerpt

Everything Android, Kotlin and other random topics

## Variables in Kotlin, differences with Java. var vs val (KAD 02)

DevFeed: [Variables in Kotlin, differences with Java. var vs val (KAD 02)](<https://devfeed.tech/articles/variables-in-kotlin-differences-with-java-var-vs-val-kad-02-27232.md>)

Original publisher: [Read original article](<https://antonioleiva.com/variables-kotlin>)

Published: 2016-11-28T00:00:00Z

Content type: tutorial

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

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

Tags: [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>)

### AI overview

A tutorial chapter explains how variables work in Kotlin and compares Kotlin's val and var declarations with Java. It covers mutable and immutable values, type inference, automatic casting, object types, and explicit numeric conversions.

### Source excerpt

Everything Android, Kotlin and other random topics

## Var and val in Java?

DevFeed: [Var and val in Java?](<https://devfeed.tech/articles/var-and-val-in-java-21990.md>)

Original publisher: [Read original article](<http://blog.joda.org/2016/03/var-and-val-in-java.html>)

Author: Stephen Colebourne (noreply@blogger.com)

Published: 2016-03-26T00:04:00Z

Content type: opinion

Language: en

Sources: [Stephen Colebourne](<https://devfeed.tech/sources/stephen-colebourne.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Java Language](<https://devfeed.tech/topics/java-language.md>), [Developer experience](<https://devfeed.tech/topics/developer-experience.md>), [code productivity](<https://devfeed.tech/topics/code-productivity.md>)

Tags: [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [coding](<https://devfeed.tech/tags/coding.md>), [developer-experience](<https://devfeed.tech/tags/developer-experience.md>), [java](<https://devfeed.tech/tags/java.md>), [java-language](<https://devfeed.tech/tags/java-language.md>), [java9](<https://devfeed.tech/tags/java9.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>)

### AI overview

This opinion examines proposed local variable type inference for Java under JEP-286, including the possible use of var, val, or let. It argues that the feature could reduce Java's verbosity while making some code reviews harder, and considers Java's history when evaluating the keyword choice.

### Source excerpt

Should local variable type inference be added to Java? This is the question being pondered right now by the Java language team. Local Variable Type Inference JEP-286 proposes to add inference to local variables using a new psuedo-keyword (treated as a "reserved type name"). We seek to improve the developer experience by reducing the ceremony associated with writing Java code, while maintaining Java's commitment to static type safety, by allowing developers to elide the often-unnecessary manifest declaration of local variable types. A number of possible keywords have been suggested: var - for mutable local variables val - for final (immutable) local variables let - for final (immutable) local variables auto - well lets ignore that one shall we... Given the implementation strategy, it appears that the current final keyword will still be accepted in front of all of the options, and thus all of these would be final (immutable) variables: final var - changes the mutable local variable to be final final val - redundant additional modifier final let - redundant additional modifier Thus, the choice appears to be to add one of these combinations to Java: var and final var var and val - but final var and final val also valid var and let - but final var and final let also valid In broad terms, I am unexcited by this feature and unconvinced it actually makes Java better. While IDEs can mitigate the loss of type information when coding, I expect some code reviews to be significantly harder (as they are done outside IDEs). It should also be noted that the C# coding standards warn against excessive use of this feature: Do not use var when the type is not apparent from the right side of the assignment. Do not rely on the variable name to specify the type of the variable. It might not be correct. Having said the above, I suspect there is very little chance of stopping this feature. The rest of this blog post focuses on choosing the right option for Java Best option for Java When thi