# Wierd behaviour of parametric type

**URL:** <https://discourse.julialang.org/t/wierd-behaviour-of-parametric-type/72520>\
**Category:** New to Julia\
**Tags:** parametric-types\
**Created:** [December 3, 2021, 12:50pm UTC](https://discourse.julialang.org/t/wierd-behaviour-of-parametric-type/72520 "2021-12-03T12:50:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruizhi\_Yang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ruizhi_yang/32/10344_2.png) [@Ruizhi\_Yang](https://discourse.julialang.org/u/Ruizhi_Yang)\
**Post date:** [December 3, 2021, 12:50pm UTC](https://discourse.julialang.org/t/wierd-behaviour-of-parametric-type/72520/1 "2021-12-03T12:50:20Z")

</div>

Hello,

I know this is kind of strange usage of parametric types, but I was wondering what’s going on. Sorry for the imprecise title, since I’m not sure how to describe this question.

Without parametric type, if I define a type and implement a wrong way to use it:

```
struct Foo
    a::String
    b::Int
end

foo = Foo(1, "hello!")

```

A method error would trigger since one cannot do the incorrect type conversion, that’s what we expect.

However if I use the parametric type in a wierd way:

```
struct Foo2{String,Int}
    a::String
    b::Int
end

foo2 = Foo2(1, "hello!")

```

No error would pop up. Instead, an instance `Foo2{Int64,String}(1, "hello!")` is generated. The specified type on `a` and `b` are violated.

What’s going on here? Any help is appreciated!

---

<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:** [December 3, 2021, 12:52pm UTC](https://discourse.julialang.org/t/wierd-behaviour-of-parametric-type/72520/2 "2021-12-03T12:52:58Z")

</div>

In the second example `String` and `Int` are not anymore what they mean in the first case, they are just generic parameters. It is the same as:

```julia
struct Foo2{A,B}
  a::A
  b::B
end

```

(of course nobody would ever use that syntax to specify generic types in a parametric type). In other words, `Int` and `String` are not reserved keywords, and here they are just assuming another meaning than the most common one. You can also do `String = "abc"`, and that will work.

---

<div class="post-metadata">

**Author:** ![Ruizhi\_Yang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ruizhi_yang/32/10344_2.png) [@Ruizhi\_Yang](https://discourse.julialang.org/u/Ruizhi_Yang)\
**Post date:** [December 3, 2021, 1:01pm UTC](https://discourse.julialang.org/t/wierd-behaviour-of-parametric-type/72520/3 "2021-12-03T13:01:02Z")

</div>

That totally make sense! Got it, thank you!
