Skip to main content
4 events
when toggle format what by license comment
Feb 16, 2016 at 1:58 comment added Parker Hoyes The example I provided is oversimplified, my actual code has a lot of methods defined for Vector such as the vector dot product, component-wise addition and multiplication, et cetera. Although I could implement these using a base class and your asArray method, those various methods wouldn't be checked at compile time (you could perform a dot-product between a scalar and a cartesian vector and it would compile fine, but fail at runtime).
Feb 16, 2016 at 1:23 comment added Groostav If you use something like the first or second solution, you can create those subclasses. Now I am also just reading on Xtend, and it seems a fair bit like Kotlin. With Kotlin, you can probably use the data class objects to easily create 10 vector subclasses. With java, assuming you can pull all of your functionality into the base class, each subclass will take 1-10 lines. Why not create a base class?
Feb 16, 2016 at 1:11 comment added Parker Hoyes My main concern isn't performance, it's compile-time checking. I would really like a solution where the size of the vector and the operations that can be performed on it are determined at compile-time (like with C++ templates). Perhaps your solution is best if you're dealing with matrices that could be up to 1000 components in size, but in this case I'm only dealing with vectors with a size of 1 - 10.
Feb 16, 2016 at 0:56 history answered Groostav CC BY-SA 3.0