https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

alex cole

01/17/2021, 2:59 AM
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

nanodeath

01/17/2021, 4:24 PM
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

alex cole

01/18/2021, 12:37 AM
I think I may just rewrite the numeric class just return ArrayND<Double> instead.
4 Views