# Vector{Integer} vs Vector{Int64} in mutable struct template

**URL:** <https://discourse.julialang.org/t/vector-integer-vs-vector-int64-in-mutable-struct-template/80175>\
**Category:** New to Julia\
**Created:** [April 27, 2022, 11:45pm UTC](https://discourse.julialang.org/t/vector-integer-vs-vector-int64-in-mutable-struct-template/80175 "2022-04-27T23:45:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kerim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kerim/32/37844_2.png) [@kerim](https://discourse.julialang.org/u/kerim)\
**Post date:** [April 27, 2022, 11:45pm UTC](https://discourse.julialang.org/t/vector-integer-vs-vector-int64-in-mutable-struct-template/80175/1 "2022-04-27T23:45:37Z")

</div>

Hi,

I can’t understand why I can’t pass Int64 instead of Integer.  
I need to create an instance of the following struct:

```julia
mutable struct MyStruct{T}
  a::Array{Integer,1}
  b::Array{Integer,1}
  c::Array{T,1}
end

a = ones(Integer, 2)
b = ones(Int64, 3)
c = ones(Float32, 3)

MyStruct(a, b, c)

```

Why I do get error:

```julia
no method matching MyStruct(::Vector{Integer}, ::Vector{Int64}, ::Vector{Float32})
Closest candidates are:
  MyStruct(::Vector{Integer}, ::Vector{Integer}, ::Vector{T}) where T at REPL[1]:2

```

As I know `Int64` is a subclass of `Integer`

How to pass `Int64` instead of `Integer`?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 27, 2022, 11:59pm UTC](https://discourse.julialang.org/t/vector-integer-vs-vector-int64-in-mutable-struct-template/80175/2 "2022-04-27T23:59:17Z")

</div>

Use `Vector{Int64}` or simply `Vector{Int}` which is the same.

Your error message would be solved using `Vector{<:Integer}` , [because of this](https://discourse.julialang.org/t/vector-float64-vector-any-false-why/80103), but probably you don’t want that, because it is an abstract type.

---

<div class="post-metadata">

**Author:** ![kerim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kerim/32/37844_2.png) [@kerim](https://discourse.julialang.org/u/kerim)\
**Post date:** [April 28, 2022, 12:12am UTC](https://discourse.julialang.org/t/vector-integer-vs-vector-int64-in-mutable-struct-template/80175/3 "2022-04-28T00:12:40Z")

</div>

> [@lmiq](#):
>
> `Vector{<:Integer}`

Thank you very much!

The approach `Vector{<:Integer} ` seems to be working though I still don’t understand the reason of that error.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 28, 2022, 12:22am UTC](https://discourse.julialang.org/t/vector-integer-vs-vector-int64-in-mutable-struct-template/80175/4 "2022-04-28T00:22:45Z")

</div>

`Vector{Int64}` is a vector that **cannot** contain, for instance, a `Int32`. Thus, `Vector{Int64}` is _not_ a subtype of `Vector{Integer}`, because the former has a _constraint_ that the later does not have.

The linked thread discusses exactly that, and [these are my notes](https://m3g.github.io/JuliaNotes.jl/stable/typevariance/) on the subject (my understanding of these things is more empirical, thus my explanation may be easier to understand than that of the computer scientists).

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [April 28, 2022, 6:11am UTC](https://discourse.julialang.org/t/vector-integer-vs-vector-int64-in-mutable-struct-template/80175/5 "2022-04-28T06:11:35Z")

</div>

> [@kerim](#):
>
> `Vector{<:Integer}`

Be aware that this has negative performance implications. You can do

```julia
mutable struct MyStruct{S<:Integer, T}
    a::Array{S,1}
    b::Array{S,1}
    c::Array{T,1}
end

```

instead.

Also, are you sure your struct must be mutable? `Array`s are already mutable in their own right, so you can modify them even if `MyStruct` itself is immutable.

---

<div class="post-metadata">

**Author:** ![kerim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kerim/32/37844_2.png) [@kerim](https://discourse.julialang.org/u/kerim)\
**Post date:** [April 28, 2022, 11:14am UTC](https://discourse.julialang.org/t/vector-integer-vs-vector-int64-in-mutable-struct-template/80175/6 "2022-04-28T11:14:39Z")

</div>

Thank you for the information

Yes the struct must be mutable asthere are also non-array elements that should be possible to modify
