Questions tagged [value-class]

62 questions
1
vote
3 answers

CLI array initialization in value class

I know that value classes don't have an default constructor as the compiler initializes all elements in this class with zero. But arrays are in a value class are not initialized: value class c_LocationVal { public: double x, y, z; …
Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45
0
votes
1 answer

How to serialize a value class with moshi so it just return it's value

I hava a value classin my android project (kotlin) and I want to parse a object, that contains this value class as type for a attribute, to json. Let's say this is my value class: @JsonClass(generateAdapter = true) @JvmInline value class…
Thomas Cirksena
  • 717
  • 2
  • 8
  • 28
0
votes
0 answers

value class in Kotlin with delegation

I would like to use something like the following, which does not compile: value class PositiveDecimal(val d: BigDecimal): BigDecimal by d { init { require(d > BigDecimal.ZERO) { "Value must be positive, was: $d" } } } so that I can…
AlexC
  • 3,343
  • 6
  • 29
  • 38
0
votes
1 answer

Kotlin working with value classes in libraries such as hibernate / jackson

Is there a way to get kotlin value classes (updated inline classes) to work with libraries such as Jackson and Hibernate and have them treat the value class simply as the underlying type? Currently I get a bunch of errors saying that there is not…
Vidde
  • 11
  • 1
  • 2
0
votes
1 answer

Scala implicit class based on type class

implicit class IntIncrement(val underlying: Int) extends AnyVal { def increment(): Int = underlying + 1 } This is valid and allows me to do something like 1.increment() I want to be able to constrain a type parameter to have this .increment()…
doliphin
  • 752
  • 6
  • 22
0
votes
0 answers

Why is Spring R2DBC Kotlin JPA adding dash and random characters when trying to map my data class fields?

This is for postgresql r2dbc coroutines etc. I've got an Entity that looks like this: @Table("entity_type") data class EntityType( @Id var id: UUID? = null, val entityTypeName: Name, // A string value class val systemSchemaVersion:…
Gritty Kitty
  • 297
  • 2
  • 12
0
votes
0 answers

Is it possible to disable inlining of value classes in Kotlin?

Goal I would like to globally disable inlining of @JvmInline value class classes via a compiler flag or something similar. I would want to do this when running unit tests but not in production. Motivation I would like to use mockk with value…
dta
  • 654
  • 4
  • 19
0
votes
1 answer

Value classes / strict typing in TypeScript

Is it possible to define value classes for strict types in TypeScript as it is done in Scala? Type aliases seems to be ignored by TypeScript "compiler": export type UserId = number; export type CarId = number; const userId: UserId = 1 const…
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
0
votes
1 answer

I have a type mismatch between 'com/google/type/LatLng' and 'com/google/protobuf/GeneratedMessage' and can't tell why

I am trying to obtain a Value class type (from google.datastore.v1) from a Long type, or even an Integer, and can't seem to be able to do so. Here is the portion of code that seems to be reluctant import com.google.datastore.v1.Value; public class…
0
votes
2 answers

Executing destructor for a value class object in Matlab

I need to control destruction of a value-class object in Matlab. The problem is as following. I have a some program (let's call it MyProg) that during execution creates a value-class object (lets call it MyValClass). MyValClass has a handle-class…
sirUjin
  • 13
  • 1
0
votes
1 answer

resource-proxy class… C++ best practices

I have a common problem to write a C++ wrapper for a C library… my main storage a C-Struct pointers who represent always a C++ class containing just ONE data filed. class MyClassC { struct MyStructS * hdl ... } creating all the constructors,…
Andreas Otto
  • 311
  • 1
  • 10
0
votes
1 answer

Inherit from value class or composite it?

I've the following classes : class A{ int x; int y; int z; public: int getX(); int getY(); int getZ(); //... } class B{ int x; int y; int z; double rotation; } class C{ int x; int y; int z; double dir; …
abdolahS
  • 663
  • 12
  • 35
0
votes
1 answer

Extended methods on Boolean value class wrapper

In my codebase I used tags to encode some information into types. As tags works using t.asInstanceOf[T @@ U] I could get away with many troubles with writing mapping between wrapped and unwrapped values. Recently I hit the wall with tagged types as…
Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64
0
votes
0 answers

Using a Scala's value class from Java

I'm using value class in Scala to avoid boxing at runtime. Eg.: trait Service { def getThing(thingId: ThingId): Thing } final case class ThingId(value: Long) extends AnyVal However, I'm using that same value class from Java code: interface…
Alban Dericbourg
  • 1,616
  • 2
  • 16
  • 39
0
votes
2 answers

scala type parameter as object type

How can I achieve this: final case class ChairId(id: String) trait GeneratorLike[TO, TC <: AbstractId] { val prefix: String def generate(): TC = TO.apply(prefix + "-" + UUID.randomUUID()) } implicit object ChairIdGenerator extends…
kpbochenek
  • 469
  • 2
  • 21