Jackal

Generics

01

Generic Classes

Generics allow classes to be defined with placeholders for data types. When instantiating, the type must be explicitly defined within angle brackets.

spec_manifest.jk
class Person<T> {
    init(name: T) {
        this.name = name
    }

    func getName() {
        return this.name
    }
}

let person = Person<String>("jack")
println(person.getName())
02

Explicit Type Instances

By providing the type in angle brackets, Jackal ensures that the passed arguments and internal logic strictly adhere to that specific data type.

spec_manifest.jk
let agePerson = Person<Int>(25)
let pricePerson = Person<Float>(99.99)

println(agePerson.getName())
println(pricePerson.getName())
← Return to Index Technical Documentation