-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Use compile-time units resolution in order to avoid number boxing.
The basic idea is the following:
- Make
Measurementan interface. And keep the implementation you already have for dynamic units. - Add an inline
Measurementimplementation like this:
inline class InlineMeasurement(<U: Units>(val value: Double): Measurement<U>- Add a resolver:
inline fun <reified U:Units> resolveUnits(): Unitsand use it to loadUnitsobject when it is needed. The resolver could work in different ways. The simplest way is to loadobjectInstancefrom reflects.
Both implementations could be used in different cases: boxing one in cases, when the Units are dynamic, inline when you can infer everything in compile-time.
t1r and pusolito
Metadata
Metadata
Assignees
Labels
No labels