# Constructors for parametric types

**URL:** https://discourse.julialang.org/t/constructors-for-parametric-types/119971
**Category:** General Usage
**Tags:** parametric-types, constructors
**Created:** [September 27, 2024, 5:28pm UTC](https://discourse.julialang.org/t/constructors-for-parametric-types/119971 "2024-09-27T17:28:37Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [September 28, 2024, 7:50am UTC](https://discourse.julialang.org/t/constructors-for-parametric-types/119971/4 "2024-09-28T07:50:04Z")

</div>

> [@eldee](#):
>
> a constructor `function Test3{C}(...)` should create an instance of type `Test3{C}`

Julia doesn’t enforce this. As you say, the error comes from the type itself, before the constructor call even occurs. The constructor’s signature cannot widen the type’s parameters.

```julia
julia> struct X{T<:Real}
         function X{T}() where T<:Number
           return "hello"
         end
       end

julia> X{Int}()
"hello"

julia> X{Int}
X{Int64}

julia> X{Complex}
ERROR: TypeError: in X, in T, expected T<:Real, got Type{Complex}

```

---

_[View the full topic](https://discourse.julialang.org/t/constructors-for-parametric-types/119971)._
