https://kotlinlang.org logo
h

hudsonb

10/30/2018, 12:50 AM
Inline classes seem neat, be interesting to try things wrapping primitive arrays
Copy code
fun vector3(x: Double, y: Double, z: Double) = Vector3(doubleArrayOf(x, y, z))

inline class Vector3(private val values: DoubleArray) {
    val x: Double
    	get() = values[0]
    
    val y: Double
    	get() = values[1]
    
    val z: Double
    	get() = values[2]
}
Though there's no way to prevent someone from creating one with a far larger
DoubleArray
than intended I guess 🤔