Home
Blogs
Questions
Jobs
Monetize

Home

About Us

Blogs

Questions

Jobs

Monetize

Post Job

banner

Questions about primary-constructor

Read more about primary-constructor

python (65.2k questions)

javascript (44.3k questions)

reactjs (22.7k questions)

java (20.8k questions)

c# (17.4k questions)

html (16.3k questions)

r (13.7k questions)

android (13k questions)

Questions - primary-constructor

Kotlin. How to declare constant?

I have class, which in primary constructor has some fields: class SomeData(val counter: Int...) { // some logic} I need to create a constant. I usually do it like this: companion object { priva...
test-img

testivanivan

kotlin

constants

companion-object

primary-constructor

val

Votes: 0

Answers: 3

Latest Answer

If your MAX_VALUE is based on other data in the object, then it is by definition not a constant. What you need instead is a read-only property. There are two easy ways to create this: First, what you ...
test-img

Moshe Katz

Kotlin: How to use custom setters in primary constructor

I don't know how to make it so that when creating an object the values of the parameters "pass through the setters" the closest I've gotten is to duplicate the code, use once in the creation...
test-img

Antonio SPR

kotlin

set

primary-constructor

Votes: 0

Answers: 1

Latest Answer

There may be many approaches to this but you're not wrong. What I'd do to achieve what you're trying to do is use the builtin error() function that throws an IllegalStateException on the JVM. class Us...
test-img

Some random IT boy

Posts

Questions

Blogs

Jobs

The ultimate platform for coders and IT specialists

About

  • Company
  • Support

  • Platform

  • Terms & Conditions
  • Privacy statement
  • Cookie policy
  • Cookie option
  • OnlyCoders © 2025  |  All rights reserved