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

Language: en

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

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [User Interfaces](<https://devfeed.tech/topics/user-interfaces.md>), [Compose Compiler](<https://devfeed.tech/topics/compose-compiler.md>), [mobile-app-performance](<https://devfeed.tech/topics/mobile-app-performance.md>), [Closure](<https://devfeed.tech/topics/closure.md>), [inlining](<https://devfeed.tech/topics/inlining.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [compose](<https://devfeed.tech/tags/compose.md>), [compose-compiler](<https://devfeed.tech/tags/compose-compiler.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [layout](<https://devfeed.tech/tags/layout.md>), [performance](<https://devfeed.tech/tags/performance.md>), [recomposition](<https://devfeed.tech/tags/recomposition.md>), [research](<https://devfeed.tech/tags/research.md>), [skip](<https://devfeed.tech/tags/skip.md>), [stable](<https://devfeed.tech/tags/stable.md>), [val](<https://devfeed.tech/tags/val.md>), [var](<https://devfeed.tech/tags/var.md>)

### AI overview

Compose can skip recomposition when a composable's parameters are considered stable. The excerpt says primitives and strings are stable, while mutable `var` fields make a class unstable; replacing them with `val` can allow a composable such as `UserDetails` to be skipped when its user has not changed. Lambdas that capture external variables may also be unstable because those variables become fields of the lambda. For simple cases, the article recommends references; for more involved lambdas, explicitly remembering them can reuse the same instance across recompositions. It says Compose Compiler Metrics and the layout inspector are used to inspect stability, restartability, skippability, and skipped recompositions. The excerpt begins discussing classes from non-Compose modules or libraries but cuts off before explaining that case or the article's other listed topics.

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

## 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: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-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

## The modifier that shouldn't be there

DevFeed: [The modifier that shouldn't be there](<https://devfeed.tech/articles/the-modifier-that-shouldn-t-be-there-25894.md>)

Original publisher: [Read original article](<https://proandroiddev.com/the-modifier-that-shouldnt-be-there-77ff941f0529?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2021-05-31T14:15:00Z

Content type: article

Language: en

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

Topics: [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>)

Tags: [android-studio](<https://devfeed.tech/tags/android-studio.md>), [behavior](<https://devfeed.tech/tags/behavior.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [call](<https://devfeed.tech/tags/call.md>), [class](<https://devfeed.tech/tags/class.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [example](<https://devfeed.tech/tags/example.md>), [extend](<https://devfeed.tech/tags/extend.md>), [fields](<https://devfeed.tech/tags/fields.md>), [interface](<https://devfeed.tech/tags/interface.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [open](<https://devfeed.tech/tags/open.md>), [open-class](<https://devfeed.tech/tags/open-class.md>), [override](<https://devfeed.tech/tags/override.md>), [programming](<https://devfeed.tech/tags/programming.md>), [properties](<https://devfeed.tech/tags/properties.md>), [property](<https://devfeed.tech/tags/property.md>), [type](<https://devfeed.tech/tags/type.md>), [val](<https://devfeed.tech/tags/val.md>)

### AI overview

Kotlin properties are final by default, but an interface property implemented with `override val` is open unless marked `final`. The excerpt's original case came from `@OpenForTesting`, which a compiler plugin uses to open the class and its fields for mocking. Overriding such a property can cause a constructor hazard: the parent initializer calls the child getter before the child backing field is initialized, producing `null`. The author advises avoiding access to non-final fields from constructors and suggests considering Mockito's inline mock maker or using fewer mocks.

### Source excerpt

The Kotlin modifier that shouldn't be therePhoto by Belinda Fewings on Unsplash Most Kotlin developers would agree that a val property is equivalent to a final property in Java. What if I tell you that this is not completely true and sometimes you might need a final val? Opposite to Java, Kotlin properties are final by default unless they are explicitly marked as open! This would mean there is no need for the final keyword, right? Let's Google that: As the internet confirmed our hypothesis, I was quite surprised when Android Studio told me to addfinal to a val: and indeed adding final would fix that: So there is a final keyword for properties but why and when should we make a val final? Let's look at this behavior using a simple example: class FinalBlog { val someProperty: String = "some" init { print(someProperty + "thing") } } "Everything works as expected here and the code will print "something" when the class is instantiated. Let's modify everything to be open: open class FinalBlog { open val someProperty: String = "some" init { print(someProperty + "thing") } } This will trigger the same type of warning I got before. This is very obvious when you think about it. The class can be subclassed and our property might be overridden. This could lead to unexpected side effects (which we will look into at the end of this post.). We can fix this simply by removing theopen modifier from the field. So, althought the warning has the same cause, it's not the exact same scenario my Android Studio was warning me on, there is no way I could add final here: non open already means final! Let's try something else: interface BlogTopic { val someProperty: String } open class FinalBlog: BlogTopic { override val someProperty: String = "some" init { print(someProperty + "thing") } } If the property is inherited from an interface, then it's open by default! Again, we will get the warning, we were looking for: And this time adding the final modifier will fix it: open class FinalBlog: Blo

## 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>), [interface](<https://devfeed.tech/topics/interface.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>), [identifier](<https://devfeed.tech/topics/identifier.md>), [Programming Language Type Systems](<https://devfeed.tech/topics/programming-language-type-systems.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>), [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>), [variables](<https://devfeed.tech/tags/variables.md>)

### AI overview

The excerpt introduces Kotlin variables as named holders for values, using a circle's radius in the circumference formula as an analogy: the radius can vary, and a variable can hold a number or other things. It frames variables, expressions, and types as the first chapter's fundamentals, but ends before giving the promised Kotlin code example.

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

## 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>), [developer-productivity](<https://devfeed.tech/topics/developer-productivity.md>), [Boilerplate](<https://devfeed.tech/topics/boilerplate.md>)

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

### AI overview

The author argues that if Java adopts local variable type inference, `var` with optional `final` fits better than `val` or `let`. JEP-286 proposes omitting explicit local types while retaining static type safety. Because Java already uses `final` to mark immutable locals, adding `val` or `let` could mix two immutability conventions in teams that mark every local `final`; `var` and `final var` preserve the existing convention. The author remains unconvinced that inference improves Java, warning that omitted types may make code reviews harder outside IDEs. Citing C# coding guidance, the text cautions against `var` when the assigned expression does not make the type apparent or when readers must infer it from the variable name.

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