Class type question? I have an untyped class in a ...
# getting-started
a
Class type question? I have an untyped class in a class primarily holding a typed array hard typed to double. I would like to move it to type the class where the class property is the same type and am able to overload operators for handling different types of boxed primitives as well as different types of the class that I have build. What is the best way to move my untyped class to a typed class.
Copy code
class ArrayND { // the class that I want to type
  var elements: Array<Double> // the array that all my functions refer too.
  var shape: Array<Int>
  constructor (ndArray: Array<Double>, shape: Array<Int>) {
    elements = ndArray
    this.shape = shape
  }
  operator fun plus(other: ArrayND): ArrayND {}
  operator fun plus(other: Double): ArrayND {}
}
I have a lot of functions that use array lists and convert them
.toTypedArray()
to create
ArrayND()
. This also has caused a problem when trying to be able to type the array and I would like to know if there is a way that if no type is given I could give it a default type of
Double
?
n
you might be able to use ReplaceWith deprecation https://stackoverflow.com/a/52203007/341772 on your elements field, and then ask IntelliJ to generate a list of deprecated use sites
a
I think I may just rewrite the numeric class just return ArrayND<Double> instead.